输出顺序

# 输出顺序

  // 输出顺序:1122
  Promise主:3
  resolve后:1004
  then:4
  setTimeout:1005

  var a = 1;
  console.log('主1:' + a++)

  setTimeout(function(){
    console.log('setTimeout:' + a++);
  },0);

  console.log("主2:" + a++);

  new Promise(function ex(resolve){
    console.log('Promise主:' + a++);
    for(var i = 0; i < 1000; i++){
      // resolve 不会使 for 循环提前结束,但 resolve 多次调用时只会取第一次的结果
      resolve(a++);
    }
    console.log('resolve后:' + a++);
  }).then(function(a){
    console.log('then:' + a++);
  })