JavaScript prototype understanding

Source: Internet
Author: User

I do not understand this thing, but the process of recording their own practice, hope to accumulate to a certain extent, can be natural and yet understanding. A lot of things I was so slowly understand, understand why it is like that, really very magical oh. Stop talking nonsense and get started.

function Person () {this. age= "AAA";} var p1=New person ();p 1.age; // AAA

From the picture we can see that p1.__proto__ and Person.prototype are not included in the age attribute
p1.__proto__ ==person.prototype

I'll create the student object again.

functionthis. Noid= "A110";} Student.prototype

From the picture we can see that Student.prototype also does not contain the Noid attribute

Now let's do this.

Let's take a student and see what happens.

New Person ();
The display results are the same as the P1.
person {age: "AAA"}
Again

student.prototype=New person (); Student;

At this time the student is still the same, without any change.

I continue to experiment, at this time instance a student;

var st1=New  Student (); st1;st1.__proto__;

Found that st1.__proto__ is not the same as p1.__proto__.
ST1.__PROTO__ is the value after the person instance
And p1.__proto__ is the person native structure

In view


At this point the St1 instance already has both the student and the person attributes, which is what we say St1 inherits the person.

A little confusing, see how Daniel explains--the article

JavaScript prototype understanding

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.