I need to do the equivalent of this in javascript:
while (typeof someObject == 'undefined') {
sleep(10); // 10ms
}
And I just can't quite figure out how to code this.
I have this:
function sleep(ms, callback, arg) {
setTimeout(function() {
callback(arg);
}, ms);
}
function waitForDef(elem) {
if (typeof elem == 'undefined') {
sleep(10, waitForDef, elem);
}
}
But it's not clear to me how to use this from my code.
Have an interval running that keeps checking on the element:
var interval = setInterval(function() {
// get elem
if (typeof elem == 'undefined') return;
clearInterval(interval);
// the rest of the code
}, 10);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With