Example:
var readBackend = function(){
var deferred = q.defer();
readData().then(function(data) {
deferred.resolve(data);
})
return deferred.promise;
}
class Test {
constructor(){
readBackend().then(function(data) {
this.importantData = data;
})
}
someFunc() {
//iterate over important data, but important data is defined
//promise didnt resolved yet
}
}
var test = new Test();
test.someFunc(); //throws exception!
Is there any way to ensure, that object properties are initiated by constructor, when I call someFunc
?
The only way which comes to my mind is creating init
function, which will return promise, but then, everytime I use my class, I would rely on init function to work properly