A preliminary understanding of JavaScript prototypes and prototype chains

Source: Internet
Author: User

Recently toss a long time, finally, JS inside the prototype and prototype chain to do a preliminary understanding;

Here, I make a metaphor:

I (child), my mother Constructor (constructor) gave birth to me, people asked my mother who was born to me, so at this time my mother will point to my father (father), that is constructor.prototype=father.

And my father can be expressed as: child.__proto__, so there are constructor.prototype===child.__proto__;

At this time, someone would ask, __proto__ what this is, this is a reference to form the prototype chain, such as child.__proto__, at this point it can be understood as, the person who gave birth to me, my father; layers of relationships, sons, fathers, grandfathers, among these __proto__, It constitutes the so-called prototype chain;


In addition, I need to note that I can borrow all the members of the father or Grandpa properties, once needed, found that they do not have the case, you can delay the prototype chain __proto__ step up to find, can borrow, found, throw undefined.

and mother Constructor constructor function all have member properties, I have also had, mother constructs me when, gave me these member attributes, once again witnessed the great motherly love!

Here is a good object prototype diagram, combined with the above understanding to see this diagram, it is clear:

Finally, this is my preliminary understanding, there is the wrong place, please advise!!

A preliminary understanding of JavaScript prototypes and prototype chains

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.