立即承诺链未按预期执行?

问题描述 投票:0回答:1

function foo(num) {
  return new Promise((resolve) => console.log(num));
}

foo(1).then(() => {
  foo(3);
});

函数 foo 返回立即解析承诺。打印了“1”,但为什么链不继续打印“3”?

javascript promise
1个回答
0
投票

你需要像这样

resolve
Promise

function foo(num) {
  return new Promise((resolve) => {
    console.log(num)
    resolve()
  });
}

foo(1).then(() => {
  foo(3);
});

© www.soinside.com 2019 - 2024. All rights reserved.