My previous question was a duplicate, I read the answer from the post it duplicated but no luck.
I've added in a bind as suggested in the answers in the SO post. But I am still getting undefined.
I have a series of promises, before each execution, I check whether the user has cancelled the promise chain.
My issue is, I cannot access 'this' inside the call back methods, a crude example is below, I cannot access the p.test variable inside getMoreData()
p.test = 'hello!';
p.init = function(){
var self = this;
this.getData()
.then(function(data) {
return self.shouldContinue(getMoreData,data).bind(self);
});
}
p.shouldContinue = function(cb, data) {
// ...
this.currentRequest = cb.call(this,data);
};
p.getData = function(){
// return ajax call
};
p.getMoreData = function(){
console.log(this.test); // undefined
// return ajax call
};