A function is also an object, and all functions have a prototype property that is created and initialized when the function is defined. Prototype is initially an object that has an constructor property that refers back to the function object that owns the prototype property.
Each object contains a shallow copy of the properties of the prototype Property object of its constructor object
Example: var o = new O (); O.PROTOTYPE.P = 5; O.P is a shallow copy of O.PROTOTYPE.P.
That is: Object o contains a shallow copy of the property P of the prototype Property object whose constructor object o
Simplification: The actual is to replace the prototype with O, so by the prototype call function, is actually o call, so can be used this
Analog prototype//function __sys__initfunctionobject (funcobj) {//1. Function objects have a prototype property initialized to the object when the functions are defined Funcobj._ Prototype = new Object (); funcobj._prototype.constructor = Funcobj;} function __sys__copyprototype (funcobj, obj) {for (var name in funcobj._prototype) {//3) when the property of the prototype object changes. Shallow copy obj[ Name] = Funcobj._prototype[name];}} __sys__initfunctionobject (SXX); Invisible function Sxx () {__sys__copyprototype (Sxx, this);//Invisible}sxx._prototype.id = 1; 2. Add an attribute to the prototype Property object var s = new Sxx (); Console.log (s);
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/88/68/wKiom1f1yCbRdF31AABFfxhkqCk480.png "title=" capture. PNG "alt=" Wkiom1f1ycbrdf31aabffxhkqck480.png "/>
This article is from the "doerthous" blog, make sure to keep this source http://doerthous.blog.51cto.com/11762533/1858915
JavaScript's prototype