I have wrote following code;
var isValid = undefined;
alert(codeEditAddress());
function codeEditAddress() {
test();
return waitFor(function() { return isValid != undefined }, function(){return isValid});
}
function test(){
setTimeout(function(){isValid = true;}, 1000);
}
function waitFor(fnReady, fnCallback) {
var check = function () {
if (fnReady()) {
fnCallback();
}
else {
setTimeout(check, 100); // wait another 100ms, and try again
}
};
check();
}
I see "undefined" in alert.
Expected result - to see "true" with delay 1 sec.
What do I wrong?
P.S. demo