From: Brandon M. <bnd...@ho...> - 2000-12-11 23:01:42
|
I think it's always better not to say MyObject.prototype=new DynObject Reasoning: We shouldn't want instance variables to be prototype variables. All variables initialized within the DynObject constructor will become part of the prototype. Why do we want this? Variables should be initialized at the time the instance is created, no sooner. I remember having a problem when I was trying to use the prototype to make sure a variable was available at the time the instance was created. I found that the variable space was shared. Especially if a varaible is an object. This could cause undefined behavior of other widgets downline. I like the idea of setting the prototypes equal.. it seems more direct, and doesn't set instances of objects as prototypes of another. ----- Original Message ----- From: "Robert Rainwater" <rra...@ya...> To: "DynAPI Development List" <dyn...@li...> Sent: Monday, December 11, 2000 3:57 PM Subject: [Dynapi-Dev] Inheritance > > I was wondering the point of this line when inheriting objects: > > MyObject.prototype = new DynObject(); > > Wouldn't it be better to say: > MyObject.prototype = DynObject.prototype > > Because in your MyObject constructor you will be saying: > this.DynObject = DynObject; > this.DynObject(); > > so all of the properties in the DynObject constructor will be > initialized, and the MyObject.prototype = DynObject.prototype line > will set all of the methods equal to the MyObject. Using the first > method you are always calling the constructor an extra time that is > not needed (or is it?). > > -- > // Robert Rainwater > > > _______________________________________________ > Dynapi-Dev mailing list > Dyn...@li... > http://lists.sourceforge.net/mailman/listinfo/dynapi-dev |