When a js object is generated:
For example, function BB (){
This. a = "kkk"
}
Var B = new BB ();
In this case, B is the prototype object pointed to by the prototype attribute of the object with BB;
The prototype object has the constructor attribute pointing to the BB function;
Therefore, alert (B. constructor = BB. prototype. constructor) // true
Here, the "with" Execution Process is to first check whether B has this attribute, and then view the attribute values in prototype, rather than simply A = B:
Add B. constructor = "ccc ";
Execute: alert (B. constructor = BB. prototype. constructor) // false; BB. prototype. constructor is still a BB function;
Let's take a look at the inheritance of kissy in taobao:
Copy codeThe Code is 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;
At the beginning, I was wrong. I don't know how to use air conditioners.