Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

真的不能在for循环里resolve完成promise吗

$
0
0
function test() {
  let m = { a: 1, b: 2 };
  let n = {};
  return new Promise(function (resolve) {
    for (let key in m) {
      n[key] = m[key];
      resolve(n)
    }
  })
}

test().then(function (r) {
  console.log(r);
})

输出结果:

{ a: 1, b: 2 }

求解,为何输出不是{a: 1}


Viewing all articles
Browse latest Browse all 14821

Trending Articles