JavaScript/Inheritance
From Wikibooks, open books for an open world
|
|
A reader has identified this page or section as an undeveloped draft or outline. You can help to develop the work, or you can ask for assistance in the project room. |
[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; }
This page may need to be