Java Reference
In-Depth Information
The examples we've seen so far have all demonstrated inheritance by inheriting properties
and methods from the prototype object. But the prototype object also has its own prototype
object, which has its own prototype object ... and so on, creating a chain of inheritance .
The Prototype Chain
We can see an example of a prototype chain by looking at the prototype of the mike instance
that we created in the last section, using the __proto__ property:
<< {"attack": function (){
return + " hits you with his " +
}, "eat": function () {
return "Mmm, this " + + " tastes great!";
}, "food": "Pizza"}
All objects have constructor functions, so we can look at what is the constructor function of
the prototype object. As you'd expect, it's the Turtle() constructor function:
mike.__proto__.constructor === Turtle;
<< true
The prototype of the prototype is an apparently empty object literal (although it's actually
not empty, as we'll see later):
<< {}
The constructor for this is the built-in Object() constructor function:
<< function Object() {
Search WWH ::

Custom Search