Home  >  Article  >  Web Front-end  >  Constructor attribute after javascript new_js object-oriented

Constructor attribute after javascript new_js object-oriented

WBOY
WBOYOriginal
2016-05-16 18:21:401206browse

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:

Copy code The code is as follows:

O = function (o) {
                    () {
                                                                                                        }                        F.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;



I misunderstood it at first, and I don’t understand that it keeps going back and forth

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn