我需要这样做,以便每次更改我的对象上的特定属性时 - 它都会在同一个对象上调用一个特殊方法。
例子:
MyObject.prototype = Object.create({
specialMethod: function() { /* ... */ }
}, {
someValue: {
set: function(value) {
/* HOW DO I ASSIGN THE VALUE TO MyObject HERE?*/
/* I can't do: this.someValue=value, that would create endless recursion */
this.specialMethod();
}
}
});
如何在属性设置器中将值分配给 MyObject?