Reputation: 2149
I have a typical call hierarchy
class A
{
mirm(){
//stuff here
}
}
class B extends A
{
constructor(){
//obtain a promise
promise().then(this.setUp)
}
setUp(){
super.mirm();
}
}
Could it be that the promise might be doing something to the scope? I would actually expect for you to be able to do something like this.mirm()
from the setUp
function since it should just follow the prototype chain. What gives? I am compiling with babel and have es2015 as target.
Upvotes: 0
Views: 350
Reputation: 66324
Passing this.setUp
detaches the current context object from the function reference when it gets invoked, therefore the this
in the super
's method is confused about where to look
Consider wrapping it instead
// arrow function preserves context
foo.then(() => this.setUp());
// OR
// binding it to explicitly give context
foo.then(this.setUp.bind(this));
Upvotes: 3