I have the following class:
let graphFactory = new GraphFactory();
function GraphFactory(){
let value = 'something';
this.release = function() {
return value;
}
}
Now, when I try to call this function from another place in my program in this way:
let newvalue = graphFactory.release();
It does not recognize graphFactory
because it takes some time to load this function.
I would like to resolve this by issuing a promise when graphFactory
is fully loaded and activated, but when I tried to add a function into GraphFactory
function like
function GraphFactory(){
let value = 'something';
this.release = function() {
graphFactoryPromise(value);
}
}
and then
function graphFactoryPromise() {
return new Promise(function(resolve,reject) {
resolve('loaded');
});
}
and calling it as
graphFactoryPromise().then(function(result) {
let newvalue = result;
});
It still doesn't work (graphFactory
is not recognized).
What would be a good solution to this?
UPDATE
What I want is to be able to call the function graphFactory.release()
only after graphFactory
is defined and loaded.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…