I'm new to JS, so I have this newbie question about right way to bind references. For example, I have this line of code in TypeScript:
this.socket.on('new_task').subscribe(this.newTask);
...
newTask(data) {
this.logEvent('new_task', data);
this.audio.playNewJob();
}
logEvent(event: string, data) {
console.log(this.TAG + event + ' triggered with received data: ' + JSON.stringify(data));
}
If I will try run this, I will get:
TypeError: this.logEvent is not a function
If I will change to:
this.socket.on('new_task').subscribe((data) => this.newTask(data));
Everything will work fine but it looks like a bad way to use JS and TS features. What is a recommended practice in this case?