ES5 vs ES6 Promises

元气小坏坏 提交于 2019-12-09 14:17:48

问题


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.



来源:https://stackoverflow.com/questions/38424517/es5-vs-es6-promises

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!