javascript - 简化 promise

标签 javascript typescript promise

如何简化此语句:

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/

相关文章:

javascript - 模块化 Promise 和 Promise.all()

javascript - 无法捕获来自第 3 方库的未处理的 Promise 拒绝

javascript - HTML 5 文件 API

javascript - 使用jquery抓取标题

c# - 构建长值数组的校验和

javascript - 用于顺序执行同步和异步函数的 jQuery Deferred 和 Promise

javascript - 为什么从 JSON 文字到类型的转换不包括函数

typescript - 了解 Typescript 定义

javascript - 将元素拖到其可滚动父 div 之外 - ( React-Draggable )

javascript - Ionic 3 中的环境特定参数