When the constructor accesses the prototype, it is usually accessed through prototype. For example, we add methods to the prototype
Person.prototype.getName = function() {}
When the instance out of new accesses the prototype, in some supported browsers
function Person() {}
var p1 = new Person();
p1.__proto__ === Person.prototype // true
Conclusion: prototype is used as a constructor to access the prototype, and __proto__ is used as an instance to access the prototype. When their identities are different, even when a method calls both at the same time, different prototypes may be accessed.
prototype is an attribute of the constructor, __proto__ is an attribute of the instance. The __proto__ attribute of an instance generated using a constructor will point to the object pointed to by the constructor's prototype attribute.
In terms of function: prototype determines the default value of proto when an object is defined using a constructor or literal form
proto is the basis for js engine prototype chain search
So the key point is that when you want to change the search method of the prototype chain, you can change the prototype chain search method of all subsequent instantiated objects by changing the constructor prototype, and use proto to modify the prototype chain search of a single object.
When the constructor accesses the prototype, it is usually accessed through
prototype
. For example, we add methods to the prototypeWhen the instance out of new accesses the prototype, in some supported browsers
Conclusion:
prototype
is used as a constructor to access the prototype, and__proto__
is used as an instance to access the prototype. When their identities are different, even when a method calls both at the same time, different prototypes may be accessed.Every object has
__proto__
, andprototype
onlyFunction
has;Maybe you can also check out these:
/a/11...
https://developer.mozilla.org...
https://developer.mozilla.org...
prototype
is an attribute of the constructor,__proto__
is an attribute of the instance. The__proto__
attribute of an instance generated using a constructor will point to the object pointed to by the constructor'sprototype
attribute.Well, that’s it.
In terms of function:
prototype determines the default value of proto when an object is defined using a constructor or literal form
proto is the basis for js engine prototype chain search
So the key point is that when you want to change the search method of the prototype chain, you can change the prototype chain search method of all subsequent instantiated objects by changing the constructor prototype, and use proto to modify the prototype chain search of a single object.