How would I execute code not from a string? Here is an example:
var ready = false;
executeWhen(ready == true, function() {
console.log("hello");
});
function executeWhen(statement, code) {
if (statement) {
window.setTimeout(executeWhen(statement, code), 100);
} else {
/* execute 'code' here */
}
}
setTimeout(function(){ready = true}, 1000);
Could I use eval();? I don't think so, I think that's only for strings.
code()?if (!statement)?'().executeWhen(ready == true, ...)should beexecuteWhen(() => ready, ...)so that you can check it repeatedly, not just at the invocation time.