1. Simple prototype chain: var song= function () {
THIS.A = 5;
this.b=6;
}//function Song () {this.a=5;}
song.prototype={
Add:function (A, b) {return a+b+this.a+this.b;},
Jian:function (A, b) {return b-a;}
}
var jum= function () {
This.name= "WTF";
}
Jum.prototype=new song ();//Let the Jum class inherit an instance of Song (including properties and methods) if you only want to song method, keep its properties of the private nature, you can set Jum.prototype =song.prototype;
Jum.prototype.constructor=jum; If it does not point to itself, then prototype.constructor points to an empty object invocation method: var songjum= new Jum (); Songjum.add (3,4); Songjum.jian (2,5); 2. Property Lookup: The property looks for its own properties, and if no more prototypes are found, no more, then go up and stick to the prototype of object. 3.hasOwnProperty
var foo = {
Hasownproperty:function () {
return false;
},
Bar: ' Here is Dragons '
};
Foo.hasownproperty (' Bar '); Always returns false
Use the {} object's hasOwnProperty and set it up and down to Foo
{}.hasownproperty.call (foo, ' Bar '); True
JavaScript (5) prototype chain (Evernote)