In order to simplify the language and retain the inherited attributes, ECMAScript's inventor designed the list.
In the data structure of the linked list is not, the list has a position equivalent to the pointer, pointing to the next structure.
So __proto__ also, whenever you define a prototype, the equivalent of the __proto__ of the instance to a struct, then the point to the struct is called the prototype of the instance.
The text is a bit of a circle, look at the picture.
Copy Code code as follows:
var foo = {
X:10,
Y:20
};
When I don't specify __proto__, Foo also reserves one of these attributes,
If there is a clear point, then the linked list is linked.
It is obvious that B and C share A's properties and methods in the image below, while having their own private properties.
__proto__ The default also has a point. It points to the highest object.prototype, while the Object.prototype __proto__ is empty.
Copy Code code as follows:
var a = {
X:10,
Calculate:function (z) {
Return this.x + This.y + Z
}
};
var B = {
Y:20,
__PROTO__: A
};
var C = {
Y:30,
__PROTO__: A
};
Call the inherited method
B.calculate (30); 60
Understand the nature of __proto__ this attribute link pointer. again to understand constructor.
When a prototype is defined, a prototype object is constructed, which is stored in the prototype method of constructing this prototype function.
Copy Code code as follows:
function Foo (y) {
This.y = y;
}
foo.prototype.x = 10;
Foo.prototype.calculate = function (z) {
return this.x+this.y+z;
};
var B = new Foo (20);
Alert (B.calculate (30));
"Reference Documentation"
Http://dmitrysoshnikov.com/ecmascript/javascript-the-core/