Cordova 是否支持 finally 方法?

Is Cordova support finally method?

我不明白为什么该代码不起作用:

this.doMagic() // <- there is a Promise which do 'reject'
  .then(_ => {
     alert('test 1') // <- this is not working (OK)
  })
  .catch(_ => {
     alert('test 2') // <- it is working  (OK)
  })
  .finally(_ => {
     alert('test 3') // <- it is not working (NOT OK)
  })

在浏览器中一切正常,但我启动模拟器,'test 3' 不工作

一开始我以为可能是alert失效了。但不是。如果您放入更多警报,它们将正常工作

总的来说,我有两个假设:

1) Cordova不支持finally

2) 不明白是怎么回事,弄错了地方

那么,哪里是真的?

Promise.prototype.finallycurrently at stage 4 of the tc39 process. Stage 4 means its finished and safe to use if your browser supports it. It will be included in the next version of the ECMAScript standard

您可以找到当前浏览器支持here。因此,如果您在 Android 设备(或模拟器)上进行测试,则需要 Chrome 63(或更高)。我猜你有一个旧版本(也许你正在使用人行横道)。

您有两个选择:

  • 使用转译器(Typescript、Babel 等)将您的 JS 转译为您的 phone
  • 支持的旧标准(例如 ES2015)
  • 使用类似 this 的解决方法