"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:3f********@olaf.komtel.net...
<snip>
Whoever has sold this approach of "private instance members"
should have told you that it breaks with prototypes being
introduced.
As Douglas Crockford appears to be responsible for inventing the
technique for emulating private instance members in JavaScript (though I
can't see that as "selling") it is probably not surprising that he has
also published pages on alternative approaches to inheritance, some of
which would address this problem.
As the emulation of private instance members is achieved by forming a
closure, in which the private members are stored, by assigning inner
functions of the constructor to public members of the object instance,
the technique results in each object instance being associated with a
closure. Assigning an super class object instance to the prototype
results in only one closure being associated with all instances of the
subclass, but the subclass instances do not each have a closure of their
own to hold any private instance members that they may want. Attaching a
closure to the prototype is an action that can be exploited as one of
the methods of emulating private static members (the other (and perhaps
preferable) method being to associate a closure with the class
constructor).
For instances of a class to inherit private instance member
functionality from a superclass they would have to explicitly create the
same closure as the superclass, which could be achieved by using the
Function.prototype.apply or call methods to apply the superclass
constructor to the - this - object (probably within the subclass
constructor).
Richard.