【问题标题】:Is Cordova support finally method?Cordova 支持 finally 方法吗?
【发布时间】:2019-02-07 22:28:15
【问题描述】:

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

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)
  })

在浏览器中一切正常,但我启动模拟器,“测试 3”不起作用

起初我认为可能是因为警报不起作用。但不是。如果您在 catch 中添加更多警报,它们将正常工作

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

1) Cordova 不支持finally

2) 我不明白发生了什么并在某处犯了错误

那么,哪里是真的?

【问题讨论】:

    标签: cordova android-emulator cordova-plugins


    【解决方案1】:

    Promise.prototype.finally 是 tc39 进程的 currently at stage 4。第 4 阶段意味着它已完成并且可以安全使用如果您的浏览器支持它。它将包含在next version of the ECMAScript standard 中。

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

    你有两个选择:

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

    【讨论】:

      猜你喜欢
      • 2020-11-11
      • 1970-01-01
      • 1970-01-01
      • 2019-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多