我想:
,我想为此创建一个通用包装,以便我可以直接制作类似waitFor(functionToWait, functionToExecute)
谢谢
答案 0 :(得分:1)
我的答案是来自以下方面的答案的组合: What is the JavaScript version of sleep()?和: How to check if function exists in JavaScript?
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function demo(cb) {
while(typeof A !== "function") {
await sleep(1000);
}
cb();
}
demo(function() { console.log("function A exists"); });
var A = function() { };