The way the literal is created using the constructor property does not point to the instance, but to the Object, the constructor creates
In the opposite way.
function Box () {}
Create the prototype object in the literal way, where {} is the object, and the Object,new object is the equivalent of {}
box.prototype={
Constructor:box,//force point to Box
Name: ' Lee ',
AGE:100,
Run:function () {
Return this.name+this.age+ "in operation ...";
}
};
Overridden a prototype object
box.prototype={
AGE:200//This will not retain any information from the previous prototype, the original prototype object and the constructor object instance before the relationship was cut off
};
var box=new box ();
alert (box.name);
alert (Box.constructor==box); True
Prototype schema creation object also has its own shortcomings, it omitted the constructor parameter initialization of the process, resulting in the lack of
The point is that the initialized values are consistent. And the biggest drawback of the prototype is its greatest advantage, that is sharing.
Four.
Several approaches to object-oriented (later) "Unfinished edition"