- 优先执行Promise实例化函数中的内容
- then中的函数被加入微任务队列
- 执行到resolve后,当前上下文执行完成后,会立刻执行下一个then中的内容
执行结果为序号顺序
new Promise(resolve => {
resolve();
})
.then(() => {
new Promise(resolve => {
console.log(100);
resolve();
console.log(101);
})
.then(() => {
console.log(111);
})
.then(() => {
console.log(222);
});
})
.then(() => {
new Promise(resolve => {
resolve();
})
.then(() => {
new Promise(resolve => {
resolve();
})
.then(() => {
console.log(444);
})
.then(() => {
console.log(666);
});
})
.then(() => {
console.log(555);
});
})
.then(() => {
console.log(333);
});
网友评论