use decorators in typescript to add some methods to a class.
//Decorator
export 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
@eventDecorator
class 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()
call this.on
IDE directly at this time. The decorator method is not recognized by extends