0

I can't understand why that code doesn't work:

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

In the browser everything works fine, but I starting the emulator, 'test 3' does not work

At first I thought that the may be because of alert does not work. But no. If you put in the catch more alerts, they will work fine

In general, I have 2 hypothesis:

1) Cordova does not support the finally

2) I don't understand what's going on and make somewhere mistake

So, where is true?

artem0071
  • 2,369
  • 3
  • 14
  • 25

1 Answers1

0

Promise.prototype.finally is currently 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.

You can find the current browser sopport here. So if you are testing on your Android device (or emulator) you need Chrome 63 (or higher). My guess is that you have an older version (maybe you are using crosswalk).

You have two options:

  • Use a transpiler (Typescript, Babel, etc.) to transpile your JS to an older standard (e.g. ES2015) which is supported by your phone
  • Use a workaround like this one
David
  • 7,387
  • 3
  • 22
  • 39