首先,我用简单的尝试界定了一名行凶者,并利用他来创建一种榜样:myobject<>code:
function MyConstructor () {};
var myobject = new MyConstructor ();
然后,我修改了<代码>prototype该信使的财产,并创建了另一个实例myobject1
。 随函附上:
MyConstructor.prototype = {};
var myobject1 = new MyConstructor ();
我重复了同样的程序,并创建了另一个案例:myobject2
:
MyConstructor.prototype = {name: 2 };
var myobject2 = new MyConstructor ();
Now I am testing the constructor
property of each instance, which is not what I expect:
myobject.constructor == MyConstructor;
//true
myobject1.constructor == MyConstructor;
//false
myobject2.constructor == MyConstructor;
//false
在研究[[类型]时,它彼此不同。
myobject.__proto__ == myobject1.__proto__
//false
myobject2.__proto__ == myobject1.__proto__
//false
Could anyone explain what happens to MyConstructor
when changing its prototype
property?