我正在尝试执行以下操作:
function SomeFunctionConstructor() {
this.someMainVariable = "someValue";
this.manipulatePrototype = () => {
this.someProtoVariable = "some new value";
}
}
SomeFunctionConstructor.prototype.someProtoVariable = "Some proto value";
var someInstance = new SomeFunctionConstructor();
现在,如果 I console.log(someInstance)
,它会打印:
{
someMainVariable: 'someValue',
manipulatePrototype: [Function]
}
现在,当我这样做时someInstance.manipulatePrototype()
,console.log(someInstance)
它会打印:
{
someMainVariable: 'someValue',
manipulatePrototype: [Function],
someProtoVariable: 'some new value'
}
为什么它someProtoVariable
直接在实例上创建一个新的而不是someProtoVariable
在原型上更新?:(