Java Reference
In-Depth Information
Every time a new object is created using the Object.create() method, the new object
inherits all the properties and methods from the parent object, which becomes the new ob-
ject's prototype. For example, we can see that the prototype object of the superman ob-
ject is the Superhuman object using this code:
Object.getPrototypeOf(superman) === Superhuman;
<< true
And we can also see that the prototype of the Superhuman object is the Human object:
Object.getPrototypeOf(Superhuman) === Human
<< true
Additionally, we can verify that the Superhuman object is the prototype of any other ob-
jects created using it:
Superhuman.isPrototypeOf(batman);
<< true
Warning: instanceof Will Fail Here
The instanceof operator will not work when objects have been created
this way. It only works when using constructor functions to create objects.
This gives the following chain of inheritance:
superman -> inherits from -> Superhuman -> inherits from
-> Human
Because of this chain, the superman object has all the properties and methods of the Hu-
man and Superhuman objects:
superman.walk();
<< "Walking"
superman.change();
Search WWH ::




Custom Search