Define a function testfunction test (){
    this.age = 10The prototype object comes with an example __proto__ attribute (pointer)newThe keyword instantiates the objectlet a = newTest () a is an instantiated object and test, in this case, is the constructor that instantiates the object a when we printconsole.log(a) outputs {constructorfn test(),
  __proto__
}
constructorThe corresponding value is thetatest() constructora.__proto__= = =test.prototype
aThe pointer to theta is equal to ustestconstructionalprototype(Stereotype property) instance objectaIts prototype is ustestconstructionalprototype(attribute)


test.prototypeAlthough he isaThe prototype of an instance but it is also an object itself.constructorfn Object(),
    __proto__} He owns it too__proto__Pointer to the__proto__I'm pointing to a functiontestSelf archetypeobject.prototypeWhy do you say that?consturctorThe value of the constructor is onefnfunctionObjectWhen we outputcosnole.log(test.prototype.__proto__) results when {constructor:fn Object()} but there is no __proto__ attribute in {} which means that this is the highest level of our prototype chain. When you output object.prototype.__proto__, the value returned isnullProto__ === test.prototype test.prototype.__proto__ === object. Prototype A prototype is test.prototype test Object. Prototype They are linked by __proto__ to form a prototype chain relationshipthis.age = 10This property is stored in the test.prototype property where the A object passesnewTest (), then instance A has the age propertyconsole.log(a.age) // The output is 10Object. Prototype. name = object'little Ming'
     console.log(a.name) // The output result is a small Ming__proto__ instance A did not find name in test.prototype but found name in the object. Prototype property pointed to by test.prototype.__proto__ There is an indirect relationship between the instance and the property value and this inheritance of the stereotype chain determines whether a property is available in the instanceconsole.log(a.hasOWNproperty('name') returns if the property is on the instancetrueOtherwise returnsfalseDetermines whether an attribute is used on the stereotype chain of an instanceconsole.log('name' inA) if returned on the prototype chaintrueOtherwise returnsfalse
     

   
     ` ``
     


     







Copy the code