【发布时间】:2023-03-30 01:05:01
【问题描述】:
我试图学习如何避免这里描述的反模式What is the explicit promise construction antipattern and how do I avoid it?
我从 JSFiddle 上的一些代码开始,但它没有输出我所期望的..
function sum1(x){
return new Promise(resolve => x+1)
}
function sum2(x){
return sum1(x)
.then(x => x+1);
}
function sum3(x){
return sum2(x)
.then(x => x+1)
}
sum3(1)
.then(console.log);
我希望它打印 4 但它什么也没打印
【问题讨论】:
标签: javascript ecmascript-6 es6-promise