我希望以下内容能够打印1 2 3
。但它会打印1 undefined 3
。我错过了什么?
var p = Promise.resolve('2');
new Promise(resolve => { console.log('1'); resolve(); })
.then(p)
.then((result) => console.log(result, '3'));
答案 0 :(得分:6)
您需要将p
变量包装在匿名函数
var p = Promise.resolve('2');
new Promise(resolve => { console.log('1'); resolve(); })
.then(() => p)
.then((result) => console.log(result, '3'));