本文介绍了JS如何拒绝内部的包装承诺?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何拒绝一个或多个内部的包装承诺?换句话说,如何使数字"3"从不打印?当前输出:
how to reject wrapper promise from inside one or? in other words, how to make number '3' never printed?Current output:
1
2
3
预期输出:
1
2
new Promise(function(resolve, reject) {
console.log(1)
resolve()
})
.then(() => console.log(2))
.then(() => { // how to reject this one if internal fails?
new Promise(function(resolve, reject) {
reject(new Error('Polling failure'));
})
.then(() => console.log(21))
})
.then(() => console.log(3))
推荐答案
似乎您只是想念 return
new Promise(function(resolve, reject) {
console.log(1)
resolve()
})
.then(() => console.log(2))
.then(() => { // how to reject this one if internal fails?
return new Promise(function(resolve, reject) {
reject(new Error('Polling failure'));
})
.then(() => console.log(21))
})
.then(() => console.log(3))
这篇关于JS如何拒绝内部的包装承诺?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!