promise面试题

Promise.resolve().then(() => {
console.log(0);
return Promise.resolve(4);
}).then((res) => {
console.log(res);
return Promise.resolve().then(() => {
console.log(1);
});
}).then(() => {
console.log(2);
}).then(() => {
console.log(3);
}).then(() => {
console.log(5);
}).then(() => {
console.log(6);
});
在chrome内部实现的Promise和标准的Promise/A+规范存在差异。浏览器内部实现的区别。
我们可以理解为,resolve或者return遇到一个Promise对象时,得到这个Promise的值之后,
会把这个值用微任务包装起来,在return值向外传递(因为后边没有.then()了,
所以是向父级的外层传递)时,会产生第二个微任务。
本文来自博客园,作者:jialiangzai,转载请注明原文链接:https://www.cnblogs.com/zsnhweb/articles/17678239.html

浙公网安备 33010602011771号