An element is added to the obj1 array, which is also added in the Obj2 array.
Do they inherit the array as a pointer? Everyone has an array of prototype this object?
//最后问一个很奇怪的问题(prototype中的array难道也只是一个指针?)
Thank you..
Reply content:
An element is added to the obj1 array, which is also added in the Obj2 array.
Do they inherit the array as a pointer? Everyone has an array of prototype this object?
//最后问一个很奇怪的问题(prototype中的array难道也只是一个指针?)
Thank you..
The first thing to understand is how to achieve inheritance.
1. The constructor has a prototype
property.
2. Each instance of a constructor has a __proto__
prototype property that points to its constructor.
3. When accessing an attribute that does not exist on an object itself, it is searched by the __proto__
prototype of its constructor.
4, so the call obj1.array
access is Person.prototype.array
; obj2.array
Person.prototype.array
5, obj1
with obj2
the common use of this one array
.
6, so whether to pass by value or reference delivery is irrelevant. Each instance was originally accessed by aprototype
Each instance does not save a copy of the constructor prototype.