No matter any article, do not understand, two times, two times do not understand, continue to see, technology is constantly upgrading, until one day you suddenly found that it is so clear ...
Prototype this piece has always wanted to summarize, the value to today only then the pen
Prototype
Defined:
JS all functions have a prototype attribute, which refers to an object, the prototype object, or the prototype. we are talking more about the prototype of the constructor, but we cannot deny that the common function also has a prototype.
Everything in JavaScript is object, each object has a __proto__ property, and the function's __proto__ corresponds to "function () {}".
The function also has the prototype property.
The prototype of an instance of the __proto__=== constructor.
Role:
Prototypes for adding properties and methods to objects
The relationship between constructor prototypes, and so on:
function P () {};
var p=new p ();
When a constructor p is created, it has a prototype property, and when new is an instance p, the __proto__ property of the example p corresponds to the prototype property of the constructor p; (p.prototype===p.__proto__)
The __proto__.constructor of the instance p corresponds to the constructor p; (P.__proto__.constructor===p () {})
thereby p.__proto__.constructor.prototype points to P.prototype (P.__proto__.constructor.prototype===p.prototype)
P.constructor===p.__proto__.constructor
P.constructor.prototype with the internal _proto_ is not the same thing, instantiate the object with _proto_, instance p is not prototype attribute, but there is internal __proto__, through __proto__ To get prototype properties and prototype methods on the prototype chain.
Prototype chain
Defined:
Everything in JavaScript is object, each object has a __proto__ property, and the __proto__ property points to its constructor prototype that instantiates it .... So it's going to form a __proto__ chain.
Prototype chain effect:
Implementing inheritance of object properties and methods
ES6 class can be inherited through the extends keyword, more convenient
If there is a wrong place, please advise! --rlflash
JavaScript prototypes and prototype chains (notes)