是否有JS一個簡單的方法做這樣的事情:安排工作的情況發生後,其他成才觸發
var scheduler = ???;
var init;
scheduler.schedule(() => console.log(init)); // does nothing
init = "Hello";
scheduler.start(); // print "Hello" because it was scheduled
scheduler.schedule(() => console.log(" world!")); // instantly print
// "world! " because the scheduler is already active.
我也忘了如何在CS調用這個,什麼這再次叫什麼?
你的意思是像'setTimeout的概念()'不? https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout –
這取決於...如果您希望調度程序回調根據設定的時間流逝來觸發,請使用setTimeout( )正如Yuriy所建議的那樣。如果您希望基於其他類型的事件,請將其註冊到相應的事件處理程序。 – RJM
什麼JS環境? – Alnitak