通过settimeout来对比异步的执行顺序
console.log(1)
setTimeout(() => {
console.log(2)
new Promise((resolve)=>{
console.log(3)
resolve()
}).then(()=>{
console.log(4)
})
}, 0);
new Promise((resolve)=>{
console.log(5)
resolve()
}).then(_=>{
console.log(6)
})
setTimeout(() => {
console.log(7)
new Promise(resolve=>{
console.log(8)
resolve()
}).then(_=>{
console.log(9)
})
}, 0);
/* 执行结果应该为:
1 5 6 2 3 4 7 8 9 */