如何简化此语句:
Foo.execSomething(k,v).then(function(){/*do nothing*/},(err) => {
console.log(err)
}).catch((err) => {
console.log(err)
});
我经常调用这些后缀(从.then
开始),我不在乎它是否成功,但我关心它何时失败,有没有更简单的方法来做到这一点?
最佳答案
仅仅使用 catch 函数怎么样?
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/catch
The catch() method returns a Promise and deals with rejected cases only. It behaves the same as calling Promise.prototype.then(undefined, onRejected).
关于javascript - 简化 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43604426/