JavaScriptProgrammer'sReference

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;

Warnings:

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.