Background: I have been tasked to help resolve an issue with the following error:
'Promise' is undefined'
Which is part of our sessionsmodel.js script:
return Promise.all(promises);
promises
is an array of actions that need to happen and if any fail it is rejected.
Question: Based on my research IE does not support Promise
so is there a work around that can be applied to this return value that will accomplish the same thing?
IE11 neither supports arrow functions nor native Promises. Use a JS transpiler (like babel) or don't use ES6 features. For Promise support you can use a library like bluebird.
'Promise' is undefined in Internet Explorer (IE 11)
The Promise.all() method takes an iterable of promises as an input, and returns a single Promise that resolves to an array of the results of the input promises. This returned promise will fulfill when all of the input's promises have fulfilled, or if the input iterable contains no promises.
Promises cannot "be executed". They start their task when they are being created - they represent the results only - and you are executing everything in parallel even before passing them to Promise. all .
Since you are using Backbone, the promises are probably jQuery promises. You could use jQuery .when
function to do the same as Promise.all
:
return $.when.apply($, promises);
For most other simple situations where you call functions like save
and fetch
, you could avoid promises completely by using the provided callbacks:
model.save({
context: this,
success: this.onModelSuccess
});
There's no need to use another library because Backbone uses jQuery already (by default), unless you don't like jQuery deferred or that you're using something else in place of jQuery.
ES6 Promise spec was implemented by "good" libraries like Q, When, RSVP, Bluebird, Lie and more...
If you want to learn more on Promises, check this link: Promises
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With