| JavaScript Inheritance | Access control |
This page or section is an undeveloped draft or outline. You can help todevelop the work, or you can ask for assistance in theproject room. |
Theinstanceof operator determines whether an object was instantiated as a child of another object, returningtrue if this was the case.instanceof is a binary infix operator whose left operand is an object and whose right operand is an object type. It returnstrue, if the left operand is of the type specified by the right operand. It differs from the.constructor property in that it "walks up the prototype chain". If objecta is of typeb, andb is an extension ofc, thena instanceof b anda instanceof c both returntrue, whereasa.constructor === b returnstrue, whilea.constructor === c returnsfalse.
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.[1]
functionCoinObject(){this.value=0;this.diameter=1;}functionPenny(){this.value=1;}Penny.prototype=newCoinObject();functionNickel(){this.value=5;}Nickel.prototype=newCoinObject();
To do: |
functionCoinObject(){this.value=0;this.diameter=1;}
| JavaScript Inheritance | Access control |