如果'_position'是Sprite的Point对象成员,其Number成员x和y以及它自己的get/set定义,我如何应用更高级别的'set'以便它能工作(编辑:我想到达“设置”功能雪碧,而不是点“设置”功能):如何在属性类型有自己的'set'时使用对象属性上的'set'?
// EDIT: example calling line, embedding context should be unimportant
// 'this' is a Sprite instance
this.position.set(x, y);
Object.defineProperties(Sprite.prototype, {
// a bunch of other properties excised here
position: {
get: function() {
return this._position;
},
set: function(_pos) {
this._position.x = this.transform.x = _pos.x;
this._position.y = this.transform.y = _pos.y;
this.transform.updateTransform();
}
}
};
目前发生什么是“this.position”转移到“position.get”属性,然后“ this.position.set“进入点设置功能。似乎试图用它自己的get/set来设置任何对象将会降到最低级别。
感觉就像一定有办法改变这种行为,但我的谷歌和stackoverflow搜索没有拿出一个答案。这很可能是我想要在这里完成的一个适当的术语,没有这个术语,我正在努力纠正这个问题。
例如: this接近,但确实在我的情况不太工作
编辑:(我不控制点源文件或功能,其中this.position.set X ,Y);举行。虽然我可以获得更改调用语法的权限,但我可以证明它不会打破实际上想要使用Point set函数的其他对象。
第一次海报然后可以听上......请让我知道如果我错过了什么或措辞的质疑不佳。 – PeteB
你的意思是做'this.position = {x:x,y:y};'?除非你指定给财产,否则你的执行者不会被执行。 – Bergi
我们看不到你的'Sprite'构造函数。它里面的所有代码都是?糟糕的编码习惯。 'Object.hasOwnProperty(propString)'将测试属性是否属于特定对象。 – PHPglue