Constructor attributes after JavaScript new

Source: Internet
Author: User

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:

CopyCodeThe 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.

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.