I'm using Q
package for an async call:
let loadPromise = Q.nfcall(m.loadObj,data);
m
is an instance of this class:
class Base {
constructor() {
this._name = null;;
}
loadObj(data) {
this._name = data;
}
}
The issue is that this
is undefined
after entering loadObj
method.
As mentioned in Q
wiki:
If you are working with methods, instead of simple functions, you can easily run in to the usual problems where passing a method to another function—like Q.nfcall—"un-binds" the method from its owner. To avoid this, you can either use Function.prototype.bind
How can I bind the right context to loadObj
method ?