在typescript中用装饰器,对某个class上增加一些方法。//Decoratorexport default function eventDecorator(target: EventEmitterType) { target.prototype.on = __event.on.bind(__event) target.prototype.off = __event.off.bind(__event) target.prototype.remove = __event.remove.bind(__event) target.prototype.Events = __event.Events target.prototype.emit = function( eventName: string, ...params: Array<string> ) { __event.emit.call(__event, eventName, this, ...params) }}//class@eventDecoratorclass Test { constructor() { let _this = this as any console.log(111111111) _this.on('aa', this.callback) _this.emit('aa', this) } callback() { console.log(this) }}new Test()这个时候直接调用this.on IDE无法识别装饰器方法,改怎么写,不用extends
添加回答
举报
0/150
提交
取消