At the beginning, the inventor of ECMAscript designed the linked list to simplify the language and maintain the inherited attributes ..
The linked list is not learned in the data structure. A position in the linked list is equivalent to a pointer and points to the next struct.
The same is true for _ proto _. When you define a prototype, _ proto _ of the Instance points to a struct, the directed struct is called the prototype of the instance.
The text is a bit difficult to say.
Copy codeThe Code is as follows:
Var foo = {
X: 10,
Y: 20
};
When I do not specify _ proto _, foo reserves such an attribute,
If there is a clear point, the linked list will be linked.
Obviously, B and c share the attributes and methods of a and have their own private attributes.
_ Proto _ is also pointed to by default. It points to the highest level of object. prototype, while the _ proto _ of object. prototype is null.
Copy codeThe Code is as follows:
Var a = {
X: 10,
Calculate: function (z ){
Return this. x + this. y + z
}
};
Var B = {
Y: 20,
_ Proto __:
};
Var c = {
Y: 30,
_ Proto __:
};
// Call the inherited method
B. calculate (30); // 60
Understand the essence of the property link pointer _ proto .. Then we can understand constructor.
When a prototype is defined, a prototype object is constructed. The prototype object is stored in the prototype method used to construct the prototype function.
Copy codeThe Code is 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]
Http://dmitrysoshnikov.com/ecmascript/javascript-the-core/