I bind a function with this code
this.process[id].on('started', this.onStartedProcess.bind(this)); // I want to pass an extra variable here.
Then, in the process, when I call this code
that.emit('started', {startTime:time, instance: that});
The following function is called
onStartedProcess(info) {
console.log(info.startTime);
}
Is it possible to pass an extra variable to the onStartedProcess
function when biding it? Something like
this.process[id].on('started', this.onStartedProcess.bind(this,otherParameter));
and use the parameter when the onStartedProcess
is called because of the emit, for example
onStartedProcess(info, otherParameter) {
console.log(info.startTime);
console.log(otherParameter);
}
I red this post about the bind method but still can't find a way to achieve what I want to do.
Edit: This is not working for me. This is what I tried
this.process[id].on('started', this.onStartedProcess.bind(this, 5));
that.emit('started', {startTime:time, instance: that});
onStartedProcess(info, otherParameter) {
console.log(otherParameter); // I was expecting the get the 5 here
}
onStartedProcess
never get called