JavaScript new constructor Property _js Object oriented

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.