Home > Article > Web Front-end > Constructor attribute after javascript new_js object-oriented
When the js object is generated:
For example: function BB(a){
this.a="kkk"
}
var b=new BB();
At this time, b is the prototype object pointed to by the attribute prototype of BB;
The prototype object has the constructor attribute pointing to the function BB;
So alert (b.constructor==BB.prototype.constructor) //true
The execution process of "have" here is to first check whether b has this attribute and then check the attribute value in prototype. It is not a simple A=B:
For example, add: b.constructor="ccc" ;
Execution: alert(b.constructor==BB.prototype.constructor) //false; BB.prototype.constructor is still a BB function;
Look at the inheritance of taobao’s kissy:
r.prototype = rp;
//alert(r.prototype.constructor==sp.constructor)
rp.constructor = r;
//alert(r.prototype.constructor== sp.constructor)
I misunderstood it at first, and I don’t understand that it keeps going back and forth