zxCoder
V2EX  ›  问与答

js 能怎么做到 setInterval 之后,在一定循环次数后, clearInterval,然后整个再返回某个值吗

  •  
  •   zxCoder · Aug 6, 2021 · 722 views
    This topic created in 1779 days ago, the information mentioned may be changed or developed.

    或者就是怎么实现比如一个函数内,每 500ms 执行一段代码,然后执行 10 次后再整个函数返回

    Biwood
        1
    Biwood  
       Aug 6, 2021
    这算是 JS 里很初级的异步逻辑,要么用 callback,要么用 Promise,多写点原生 JS 代码,熟悉一下回调、同步和异步、Promise 这些概念吧,这些都熟悉了之后用 async/await 语法才能达到你期望的写法(即用同步的方式写异步任务)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2357 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 01:31 · PVG 09:31 · LAX 18:31 · JFK 21:31
    ♥ Do have faith in what you're doing.