I can't figure out how to correct the context of my methods.
I have this class:
export default class Handler {
constructor() {
// init
}
handleMessage(channel, user, message) {
this.handleDefault(channel, user, message);
}
handleDefault(chanenl, user, message) {
// do stuff
}
}
it is called by this method and class
export default class Bot {
constructor() {
this.irc = irc // has an event emitter irc.event
this.handler = new Handler();
this.readIRC();
}
readIRC() {
this.irc.event.on('message', this.handler.handleMessage);
}
}
The problem is in the first class inside handleMessage is this not the class anymore but the eventEmitter so I can't call my handleDefault method.
How do I work with contexts corretly in ES6 ?