A lightweight Promise polyfill based on Promises/A+ compliant $.Deferred from jQuery 3.
jquery-promise is for you if the following conditions apply.
- You are already using jQuery 3+ for independent reasons.
- You need a polyfill for the ES6
Promiseinterface, for example because you are transpiling
- You want your polyfill to be as small as possible.
$ npm i @dhl-uu/jquery-promise
This will only put the polyfill in global scope if there is no
Promise global already. The polyfill implementation is also the default export of the module.
This is a very thin wrapper around
jQuery.Deferred. Our polyfill
Promise interface has the same constructor, static methods and instance methods as the standard. However, objects returned after chaining
.finally lack the
.finally method themselves. This is beyond our control, because jQuery constructs promise objects as plain objects in a closure and there is no prototype that we can extend. This is unlikely to cause problems in practice. You still get Promises/A+ compliant then-able objects.