老生常谈之宏任务微任务

52次阅读

共计 385 个字符,预计需要花费 1 分钟才能阅读完成。

 const promise = new Promise((resolve, reject) => {console.log(1);
    resolve('22222');
    console.log(2);
    setTimeout(() => {console.log(7)
    })
  }).then((res)=>{console.log('1111')
    console.log(res)
  });

  promise.then(() => {console.log(3);
    setTimeout(() => {console.log(6);
    })
  })
  setTimeout(() => {console.log(5);
  })
  console.log(4);
VM300:2 1
VM300:4 2
VM300:22 4
VM300:9 1111
VM300:10 22222
VM300:14 3
undefined
VM300:6 7
VM300:20 5
VM300:16 6

正文完
 0