first, make a few points clear:1. In JS, everything is the object. A method (Function) is an object, and the prototype (Function.prototype) of a method is an object. Therefore, they all have characteristics that are common to objects.
That is, an object has an attribute __proto__, which can be called an implicit prototype, and an implicit prototype of an object points to the prototype of the constructor that constructs the object, which ensures that the instance has access to the properties and methods defined in the constructor prototype.
2. Method (Function) method This special object, in addition to the same as other objects have the above _proto_ attribute, but also has its own unique properties--prototype properties (prototype), this property is a pointer to an object, The purpose of this object is to include properties and methods shared by all instances (we call this object a prototype object). The prototype object also has a property called constructor, which contains a pointer to the original constructor.
Well, knowing the two basic points, let's take a look at the picture above. 1. Constructor Foo () the prototype property of the constructor Foo.prototype points to the prototype object, there are common methods in the prototype object, and all instances of the constructor declaration (this is F1,F2) can share this method.
2. Prototype object Foo.prototypeFoo.prototype preserves the method of instance sharing, with a pointer constructor the constructor.
3. Examples F1 and F2 are two instances of Foo, which also have attribute __proto__, which points to the constructor's prototype object, which can be like all the methods of accessing the prototype object as described in 1 above.
In addition:Constructor Foo () Besides being a method and an object, it also has the __proto__ attribute, which point to whom?
The prototype object that points to its constructor, chant. The constructor of a function is not just functions, so the __proto__ here point to Function.prototype.
In fact, in addition to Foo (), Function (), Object () is the same reason.
The prototype object is also the object Ah, its __proto__ property, and to whom?
Similarly, the prototype object that points to its constructor is Bai. This is object.prototype.
Finally, the __proto__ property of Object.prototype points to null.
Summary:1. The object has an attribute __proto__, a prototype object that points to the constructor of the object.
2. In addition to the attribute __proto__, there is a property prototype,prototype the prototype object that points to the method. Doris
Links: https://www.zhihu.com/question/34183746/answer/58155878
Source: Know
Understand JavaScript's prototype and __proto__