承诺嵌套在javascipt中如何工作[重复]

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

为什么它打印promisepending? 我期待它可能会给出承诺>或承诺<1>

let k = new Promise((resolve, reject) => {
  let a = new Promise((res, rej) => {
    res(1);
  });
  resolve(a);
});

console.log(k); // see browser console for promise state

javascript promise es6-promise
1个回答
0
投票

如果你等到承诺得到解决,这会有所帮助

let k = new Promise((resolve, reject) => {
  let a = new Promise((res, rej) => {
    res("boink");
  });
  resolve(a)
});

k.then(res => console.log(res))
© www.soinside.com 2019 - 2024. All rights reserved.