Java Reference
In-Depth Information
Finding Out the Prototype
There are a number of ways to find the prototype of an object. One way is to go via the
constructor function's prototype property:
raph.constructor.prototype;
<< {"attack": function (){
return this.name + " hits you with his " + this.weapon;
}, "weapon": "Hands"}
Another way is to use the Object.getPrototypeOf() method, which takes the ob-
ject as a parameter:
Object.getPrototypeOf(raph);
<< {"attack": function (){
return this.name + " hits you with his " + this.weapon;
}, "weapon": "Hands"}
Many JavaScript engines also support the secret __proto__ property. This is known as
dunder proto , which is short for “double underscore proto.” It is not an official standard,
but it's supported in most modern browsers and is expected to be standardized in the next
version of JavaScript:
raph.__proto__
<< {"attack": function (){
return this.name + " hits you with his " + this.weapon;
}, "weapon": "Hands"}
Every object also has a isPrototypeOf() method that returns a Boolean to check if
it's the prototype of an instance:
Turtle.prototype.isPrototypeOf(raph)
<< true
Search WWH ::




Custom Search