The prototype object is also a normal object, is an object with an implicit __proto__ property, the prototype may have its own prototype, if the prototype of a prototype object is not NULL, we call it a prototype chain. A prototype chain is a (finite) object chain of objects that are used to inherit and share attributes.
Properties in a prototype object can be shared by multiple instances. The prototype object exists in the constructor's properties (prototype), and the prototype value is an object type data (object).
What are the property values for JavaScript data objects, and give a few simple chestnuts:
Writable: Whether the value of this property can be changed;
Configurable: Whether the configuration of this property can be deleted, modified;
Enumerable: Whether this property can be traversed in the for...in loop or listed in the Object.keys.
Value: The value of the property.
When you build an object, you place the method in the prototype object of the constructor, which resolves the memory redundancy problem caused by creating multiple instances of the object. (The principle of resolving memory redundancy is because the properties in the prototype object can be shared by multiple instances)
The lookup rule for the prototype chain is this: When invoking an object's properties, look for the property from the instance itself, and use it directly if it can be found, or look in the prototype object of the instance, and if it cannot be found in the prototype object, it will continue to find the prototype object under the prototype object. The dynamic Create property is executed until the prototype of the object base class is found, or if it is not found. (The prototype object described above refers to the __proto__ attribute)
In JavaScript, there is a function that, when performing an object lookup, never finds a prototype, this function is hasOwnProperty
When an attribute in an object is assigned a value, it is first looked up from the instance itself, and the attribute in the instance overrides the attribute value in the instance, otherwise the attribute is created directly in the instance. (does not affect the same name attribute in the prototype)
The prototype chain in JavaScript