I'm trying to update a value outside of the scope of a promise function but am having difficulty wrapping my head around how to do so. I thought setting self = this would correct scope issues as suggested here, but self.value is still 0 outside of the scope of the promise. The relevant code is below.
window.App = {
foo: function() {
var self = this;
self.value = 0;
self.func1 = function() {
func2().then(function(result1) {
return func3(result1);
}).then(function(result2) {
self.value = result2;
})
}
},
bar: function() {
var fooObject = new this.foo();
fooObject.func1();
},
baz: function() {
var fooObject = new this.foo();
func4(fooObject.value);
}
}
How would I be able to set the value of self.value inside the promise? I would like to access this value later on in the code within App via foo.value.