【发布时间】:2022-01-05 16:25:08
【问题描述】:
以下是我的代码 -
const fn = () => new Promise((resolve, reject) => reject());
let promise = fn();
promise
.then(() => console.log('Success 1'))
.then(() => console.log('Success 2'))
.then(() => console.log('Success 3'))
.catch(() => console.log('Error 1'))
.then(() => console.log('Success 4'))
.catch(() => console.log('Error 2'))
.then(() => console.log('Success 5'))
.catch(() => console.log('Error 3'))
返回 -
"Error 1"
"Success 4"
"Success 5"
我的问题是,当一个承诺通过输出Error 1 解决时,为什么Success 4 和Success 5 会登录控制台?
【问题讨论】:
-
因为catch也返回一个promise
-
有人有一个非常好的欺骗目标吗?我敢肯定有一个,但我发现的不同之处足以令人困惑。
-
@T.J.Crowder 这个怎么样? Executing then after catch
-
@JeffBowman - 完美!
标签: javascript ecmascript-6 promise callback