1 回答
TA贡献1854条经验 获得超8个赞
您需要在 getter 中返回目标:
class SomeClass {
public readonly name: String;
public originalData: Array<number> = [];
private arrayHandler = {
set(
target: Array<number>,
prop: number,
val: any,
reciever: any
): boolean {
console.log("PROXY HANDLER SET");
target[prop] = val;
return true;
},
get(target: Array<number>, prop: number): any {
console.log("PROXY HANDLER GET");
return target[prop];
},
};
public proxyToArray: any = new Proxy(this.originalData, this.arrayHandler);
constructor(name: String) {
this.name = name;
}
}
let item = new SomeClass("item-1");
item.proxyToArray.push(1);
添加回答
举报