When trying to access the class properties (or methods) from another scope, I find myself having to store it in a local variable within the function scope.
class MyClass {
constructor(API) {
this.API = API;
this.property = 'value';
}
myMethod() {
var myClass = this; // Storing class in a local variable is necessary
this.API.makeHttpCall().then(function(valueFromServer) {
// Accessing via local variable
myClass.property = valueFromServer;
});
}
}
Having to do this for every method seems inefficient. Is there an alternative approach?