When you create a subclass in JavaScript, it is done by building a constructor function. To be completely correct, the constructor should be linked by the constructor property of the prototype property. We overwrite the prototype as an object is created, however the constructor is inherited from the object that was cloned. We need to set the constructor manually. That is done like this:
MyNewClass.prototype.constructor = MyNewClass;
There are some versions of Netscape Navigator that set the constructor property to be read-only and this prohibits a script from changing it.
In Navigator 4, a non-portable low level internal variable can be 'hacked' to fix up the prototype rather than the constructor. This uses the __proto__ internal property.
See also: | __proto__, Anchor object, Superclasses |
Prev | Home | Next |
SUB object | Up | SubmitButton object |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |