简体   繁体   English

Babel-Polyfill未实现的承诺

[英]Uncaught promise with babel-polyfill

There is the following simple code: 有以下简单代码:

  function getPromise() {
    return new Promise((resolve, reject) => {
      reject();
    })
  }

  getPromise().then(() => {});

As you can see I just return promise which are always reject, but I don't want to catch it. 如您所见,我只是返回始终被拒绝的承诺,但我不想抓住它。 So, I see in console error: 所以,我在控制台中看到错误:

Uncaught (in promise)

I don't want to catch it, but I don't want to see this error. 我不想抓住它,但是我不想看到这个错误。 What should I do? 我该怎么办? I use babel-polyfill. 我使用babel-polyfill。

You are rejecting a promise and not catching it. 您正在拒绝诺言,而不是兑现诺言。 Simply catch the error and do nothing with it. 只需捕获错误,然后对其进行任何操作即可。 That is the only way to handle rejected promises in vanilla JS until the finally method makes it into the spec, probably for ES2018 . 这是处理香草JS中被拒绝的诺言的唯一方法, 直到finally方法成为规范( 可能适用于ES2018)为止

getPromise().then(() => {}).catch(() => {});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM