When a JS object is generated:
such as: function BB (a) {
This.a= "KKK"
}
var b=new BB ();
At this time B is the object has the BB attribute prototype to the prototype object;
The prototype object has a constructor attribute pointing to the BB function;
So alert (b.constructor==bb.prototype.constructor)//true
Here the "with" the implementation process is to see if B has this attribute to see the prototype in the value of the property, is not a simple a=b:
such as add: b.constructor= "CCC";
Implementation: Alert (B.constructor==bb.prototype.constructor)//false; BB.prototype.constructor is still a BB function;
Look at the inheritance of Taobao's Kissy:
Copy Code code as follows:
o = function (o) {
function F () {
}
F.prototype = O;
return new F ();
},
SP = S.prototype,
RP = O (sp);
R.prototype = RP;
Alert (R.prototype.constructor==sp.constructor)
Rp.constructor = R;
Alert (R.prototype.constructor==sp.constructor)
R.superclass = SP;
Just beginning to understand the wrong, do not understand all the time back and forth air conditioner