I wanna know whether JS promises were a part of es5? If so, why it doesn't work sometimes in older browsers and we have to add a polyfill for the same. Also, which polyfill should be added in that case, an es5 one or es6? I have a little confusion regarding the same.
问题:
回答1:
ES5 did not have promises. Libraries like jQuery or Angular had their own custom and non-standard promise implementations.
Popular Promise implementations for use with ES5 are Bluebird (which is compatible with the ES6 standard) and Q (which was not originally compatible with the ES6 standard- though seems to be moving that direction) and RSVP.
Neither are actual polyfills in that they don't get out of the way if native promises are present because they add additional features.
There are some pure polyfills for ES6 promises. Here's one that is a subset of RSVP: https://github.com/stefanpenner/es6-promise.
There are reasons to use more than a polyfill as you can read here: Are there still reasons to use promise libraries like Q or BlueBird now that we have ES6 promises?
Asking for a recommendation of a specific polyfill library is considered off-topic here on Stack overflow so I won't comment on that.