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