js 顺序执行代码

      new Promise(function(resolve){
          console.log('马上执行for循环');
          for(var i = 0; i < 1000; i++){
              resolve();
              console.log(i);
          }
      }).then(function(){
          console.log('执行then函数')
      });
new Promise(function(resolve){
    console.log('马上执行for循环');
    for(var i = 0; i < 1000; i++){
        console.log(i);                  // 如果for循环里面有调取接口的,可能出现for已经结束了,接口还没调取完
    }
    resolve(i);

}).then(function(data){
    console.log('执行then函数' + data)
});

posted @ 2020-04-09 22:27  盘思动  阅读(942)  评论(0编辑  收藏  举报