【发布时间】:2020-06-26 03:18:35
【问题描述】:
我是 js 新手,很难理解 Promise 和嵌套 Promise。为什么当我的承诺返回错误时,它仍然加载嵌套的.then()。这是我的示例代码。
firstFunction()
.then(success(){
//some statement
return secondFunction();
}, error(err){
//logging the err.
})
.then(success(){
//some statement for secondFunction
},error(err){
//logging error for second function
})
当我的 firstFunction 正常时,它们工作正常,加载 firstfunction .then,然后是 secondFunction.then,但是当第一个函数失败时,它会转到它的 :error(err) 函数,但仍然在我的 secondFunction 中执行我的代码。那么()?
【问题讨论】:
标签: javascript ecmascript-6 es6-promise