function foo(num) {
return new Promise((resolve) => console.log(num));
}
foo(1).then(() => {
foo(3);
});
函数 foo 返回立即解析承诺。打印了“1”,但为什么链不继续打印“3”?
你需要像这样
resolve
Promise
:
function foo(num) {
return new Promise((resolve) => {
console.log(num)
resolve()
});
}
foo(1).then(() => {
foo(3);
});