Promise.resolve().then(() => {
console.log(1)
}
).then(() => {
console.log(3)
}
).then(() => {
console.log(5)
}
).then(() => {
console.log(7)
}
).then(() => {
console.log(9)
}
)
Promise.resolve().then(() => {
console.log(2)
}
).then(() => {
console.log(4)
}
).then(() => {
console.log(6)
}
).then(() => {
console.log(8)
}
).then(() => {
console.log(10)
}
)
请问输出什么结果?
输出 1 ,2,3,4,5,6,7,8,9,10
当我们向代码中添加promise.resolve
Promise.resolve().then(() => {
console.log(1)
}
).then(() => {
console.log(3)
return Promise.resolve(4)
}
).then(() => {
console.log(5)
}
).then(() => {
console.log(7)
}
).then(() => {
console.log(9)
}
)
Promise.resolve().then(() => {
console.log(2)
}
).then(() => {
console.log(4)
}
).then(() => {
console.log(6)
}
).then(() => {
console.log(8)
}
).then(() => {
console.log(10)
}
)
这个会输出什么?
Promise.resolve().then(() => {
console.log(1)
return Promise.resolve(1)
}
).then(() => {
console.log(3)
}
).then(() => {
console.log(5)
}
).then(() => {
console.log(7)
}
).then(() => {
console.log(9)
}
)
Promise.resolve().then(() => {
console.log(2)
}
).then(() => {
console.log(4)
}
).then(() => {
console.log(6)
}
).then(() => {
console.log(8)
}
).then(() => {
console.log(10)
}
)
得出结论,只要你添加了Promise.resolve就会延长两个时序