看板 Ajax 關於我們 聯絡資訊
最近剛踏入javascript的領域 我想在一個迴圈中重複執行某一個function 這個function是個同步函數 我希望每次都做完這個function才延遲 大概像是下面這樣 while (cnt<999) { function() delay() cnt++ } 我試過了setTimeout 結果跟預期的不同 用了promise跟then的作法也是不如預期 請問各位大神有什麼方法可以做到我要的效果呢? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 49.218.50.232 ※ 文章網址: https://www.ptt.cc/bbs/Ajax/M.1530780652.A.8D6.html
chu2815: pt/Guide/Iterators_and_Generators07/05 18:30
chu2815: https://goo.gl/kUbU7 類似這個概念嗎07/05 18:31
sckm160913: new Promise(r => setTimeout(r, 5000))07/05 21:40
sckm160913: 還要await07/05 21:42
y3k: async ()=>07/06 13:42
xdraculax: 這情況用 setInterval 比 setTimeout 好點07/07 10:00
感謝幫忙解答的各位:) ※ 編輯: ggbast (49.214.51.121), 07/09/2018 09:58:39