From: Nicola M. <nic...@ho...> - 2001-01-20 22:55:25
|
So what is the answer on that ?! I think I'm missing something Y _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com |
From: Pascal B. <pa...@dy...> - 2001-01-21 10:25:48
|
Ok, now that I'm more awake then yesterday, here's the explanation of the problem: doing this: b.prototype=a.prototype this makes the prototypes identical (so the objects are identical) when you do this: b.prototype=new A you make the B objects prototype be an instance of the A object, not copy it's prototype, but merely make a reference that the prototype should have all properties and methods in object A. Also the constructor is called an extra time, but does not require extra memory, because it only makes a reference to it, not copy all methods and functions. This is again something thats hard to explain, so possibly harder to understand.. I can't recall the Javascript reference that explains all this.. but do a search for "Javascript object inheriting" and it should lead you to some netscape site containing the info. cya, Pascal Bestebroer pa...@dy... http://www.dynamic-core.net > -----Oorspronkelijk bericht----- > Van: dyn...@li... > [mailto:dyn...@li...]Namens Robert > Rainwater > Verzonden: zaterdag 20 januari 2001 23:00 > Aan: Pascal Bestebroer > Onderwerp: Re[2]: [Dynapi-Widgetdev] aggregating prototypes > > > > I totally agree. I tried doing that with the dynapi, and it crashed > and burned. Especially when trying mulitiple inheritance. > > Even though the constructor is always called an extra time, it makes > the inheritance chain work. > > -- > // Robert Rainwater > > On 1/20/2001, 4:56:21 PM EST, Pascal wrote about > "[Dynapi-Widgetdev] aggregating prototypes": > > > now try some more interesting constructions with multiple instances of a > > certain widget > > and of making another object with is based on widget B. > > > Trust me on this one (please) that this is the way to do > correct prototyping > > in Javascript. > > There are netscape documents on the net that verify this :-) > > > cya, > > > Pascal Bestebroer > > pa...@dy... > > http://www.dynamic-core.net > > >> -----Oorspronkelijk bericht----- > >> Van: dyn...@li... > >> [mailto:dyn...@li...]Namens > Theo Bebekis > >> Verzonden: zaterdag 20 januari 2001 22:46 > >> Aan: dyn...@li... > >> Onderwerp: [Dynapi-Widgetdev] aggregating prototypes > >> > >> > >> Hi > >> > >> Is there any difference between the two? > >> > >> 1st case > >> --------------------------------- > >> function A() { } > >> function B() { } > >> B.prototype = new A() > >> > >> 2nd case > >> --------------------------------- > >> function A() { } > >> function B() { } > >> B.prototype = A.prototype > >> > >> > >> > >> I'm getting the same result in either case. > >> Please, try the following code by changing > >> the prototype assignment > >> > >> <script language="Javascript" > > >> function A() { } > >> A.prototype.say = function() {alert("a say")} > >> > >> function B() { } > >> B.prototype = A.prototype > >> B.prototype.A_say = A.prototype.say > >> B.prototype.say = function() > > >> alert("b say") > >> this.A_say() > >> } > >> > >> function C() { } > >> C.prototype = B.prototype > >> C.prototype.B_say = B.prototype.say > >> C.prototype.say = function() > > >> alert("c say") > >> this.B_say() > >> } > >> > >> var c = new C() > >> c.say() > >> </script> > >> > >> > >> > >> Theo > >> > >> ----------------------------------- > >> Theo Bebekis > >> Thessaloniki, Greece > >> be...@ot... > >> ----------------------------------- > >> > >> _______________________________________________ > >> Dynapi-Widgetdev mailing list > >> Dyn...@li... > >> http://lists.sourceforge.net/lists/listinfo/dynapi-widgetdev > >> > > > > _______________________________________________ > > Dynapi-Widgetdev mailing list > > Dyn...@li... > > http://lists.sourceforge.net/lists/listinfo/dynapi-widgetdev > > > > _______________________________________________ > Dynapi-Widgetdev mailing list > Dyn...@li... > http://lists.sourceforge.net/lists/listinfo/dynapi-widgetdev > |
From: Nicola M. <nic...@ho...> - 2001-01-21 20:47:12
|
gotta u thanks Y _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com |