We create an object using a constructor:

2, the prototype

Each function has a Prototype property, which we see in various examples, such as:

So what does this function’s Prototype attribute point to? Is it the prototype of this function? In fact, the function’s prototype property points to an object that is the prototype of the instance created by calling the constructor, namely person1 and person2 in this example. So what is a prototype? You can think of it this way: every JavaScript object (except null) is associated with another object when it is created, and this object is called a prototype, from which each object “inherits” properties. Let’s use a diagram to show the relationship between constructors and instance stereotypes:

proto

So let’s update the diagram:

In this example, we set the name property of person, so we can read ‘name of this person’. When we remove the name property of person, we read Person.name, Person. Proto == Person. Prototype (‘ name ‘, ‘name’, ‘name’, ‘name’, ‘name’, ‘name’, ‘name’) What is the archetype of the archetype? In the previous section, we said that a prototype is also an object, and since it is an object, we can create it in the most primitive way, that is

The prototype Object is generated by the Object constructor. The __proto__ of the instance points to the prototype constructor.

By the way, the chain of connected prototypes in the diagram is the prototype chain, the blue line. (7) Finally, add and correct some loose points in this article: