# 实现异步循环打印

http://www.conardli.top/docs/JavaScript/异步循环打印.html (opens new window)

使用promise + async await实现异步循环打印

    var sleep = function (time, i) {
      return new Promise(function (resolve, reject) {
        setTimeout(function () {
          resolve(i);
        }, time);
      })
    };


    var start = async function () {
      for (let i = 0; i < 6; i++) {
        let result = await sleep(1000, i);
        console.log(result);
      }
    };

    start();

Last Updated: 8/4/2019, 9:33:54 PM

单例模式 (opens new window)图片懒加载 (opens new window)

上次更新: 11/8/2024, 10:19:43 AM