JavaScript/Inheritance
From Wikibooks, the open-content textbooks collection
[edit] instanceof operator
The instanceof operator determines if an object was instantiated as a child of another object, returning true if this was the case.
[edit] Inheritance by Prototypes
The prototype of an object can be used to create fields and methods for an object. This prototype can be used for inheritance by assigning a new instance of the superclass to the prototype.
function CoinObject() { this.value = 0; this.diameter = 1; } function Penny() { this.value=1; } Penny.prototype = new CoinObject(); function Nickel() { this.value=5; } Nickel.prototype = new CoinObject();
[edit] Inheritance by functions
function CoinObject() { this.value = 0; this.diameter = 1; }