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)
});


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM