文章
console.log('1');
setTimeout(function() {
console.log('2');
process.nextTick(function() {
console.log('3');
})
new Promise(function(resolve) {
console.log('4');
resolve();
}).then(function() {
console.log('5')
})
})
process.nextTick(function() {
console.log('6');
})
new Promise(function(resolve) {
console.log('7');
resolve();
}).then(function() {
console.log('8')
})
setTimeout(function() {
console.log('9');
process.nextTick(function() {
console.log('10');
})
new Promise(function(resolve) {
console.log('11');
resolve();
}).then(function() {
console.log('12')
})
})
- 整體代碼作為一個宏任務進入,開始第一個回圈
- 執行同步 //1
- stime1 放入宏任務佇列任務
- process.nextTick ,process1進入微任務佇列,
- new promise 立即執行 //7
- then1放入微任務佇列
- stime2 放入入宏任務佇列
- 完成第一個宏任務(整體代碼script)
- 執行微任務process1 then1 //6 8
- 結束第一次回圈,開始第二次回圈,執行宏任務stime1,//2
- process2放入微佇列中
- new promise //4
- 添加微任務then2
- 執行微任務process2 then2 結束第二次回圈 // 3 5
- 執行宏任務stime2 // 9
- 新增微任務process3
- new promise //11
- 添加微任務then3
- 執行process3 then3 結束第三次回圈 // 10 12
所以輸出結果1 7 6 8 2 4 3 5 9 11 10 12
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/231406.html
標籤:其他
上一篇:npm的下載與安裝
下一篇:博客中css樣式的正確設定
