「_position」が Sprite の Point オブジェクト メンバーであり、Number メンバー x と y、および独自の get/set 定義を使用する場合、これが機能するように、より高いレベルの「set」を適用するにはどうすればよいですか (編集: Point の 'set' 関数ではなく、Sprite の '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」が Point set 関数に渡されます。独自の get/set を使用してオブジェクトを「設定」しようとすると、最低レベルに落ちるようです。
この動作を変更する方法が必要なように感じますが、私のグーグル検索とスタックオーバーフロー検索では答えが見つかりません。ここでやりたいことを表す適切な用語がある可能性がありますが、それがなければ、質問というフレーズを正しく理解するのに苦労しています。
例: これは近いですが、私の状況ではうまくいきません
編集: Point のソース ファイル、または this.position.set(x,y); の関数は制御しません。保持されています。ただし、実際にポイント セット関数を使用したい他のオブジェクトを壊さないことを証明できれば、呼び出し構文の変更の許可を得ることができるかもしれません。