javascript – 在前端听取被拒绝的承诺

使用node.js,我们可以使用以下方法监听被拒绝的承诺:

process.on('unhandledRejection', (reason, p) => {
  console.log('Unhandled Rejection at:', p, 'reason:', reason);
  // application specific logging, throwing an error, or other logic here
});

这是在前端听取未处理的拒绝的最佳方式吗?

https://developer.mozilla.org/en-US/docs/Web/Events/unhandledrejection

最佳答案 是的,window.addEventListener(“unhandledrejection”,…)是节点的process.on(‘unhandledRejection’,…)的前端.这不是听“他们”的“最佳”方式,这是唯一的方法.

点赞