需求,我有大量需要用到同一个自定义模板的get set 函数如:
@property(Button)
private _button: Button;
@property(Button)
private set button (value) { this._signinButton = value; }
private get button () {
if (!this._button) {
this._button = this.getComponentByPath('Button', Button);
}
return this._button;
}
想用装饰器包装下,类中减少重复的代码量。如:
@mygetset('Button', Button)
button: Button
自己尝试了下,在target.constructor.__ccclassCache__.proto.properties
中增加了get set函数并没有生效,希望有研究过的大佬指点一二。