本來想利用裝試者來監聽數據更改. 代碼如下:export function fireBind(type:string) { return function (taget:any, key:string, descriptor:TypedPropertyDescriptor<any>) { let oldSet = descriptor.set;
descriptor.set = function(val){
MessageCenter.fire(new ModelEvent(type, val)); console.log('1111');
oldSet.call(null, val); console.log('2222');
}
}
}class Test { private _selected; @fireBind(EventState.GOODS_SELECTED) public set selected(data:any) { this._selectedData = data; console.log('this._selectedData:', this._selectedData);
} public get selected(){ return this._selectedData;
}
}調用 :const T = new Test();
T.selected = 'test';console.log(T.selected);輸出結果:1111this._selectedData: testnull;
誰使用過typescript Decorators特性?
海綿寶寶撒
2018-08-07 10:09:00