代码拉取完成,页面将自动刷新
简体中文 | English
✨ A ES2021 Promise implementation based on ES3 has high compatibility, and comply with ECMA-262 and Promises/A+
The best way to learn
Promise
is to implement it.
Ability | Version | Support |
---|---|---|
new Promise(executor) | ES2015 | ✔ |
Promise.prototype.then(onFulfilled, onRejected) | ES2015 | ✔ |
Promise.prototype.catch(onRejected) | ES2015 | ✔ |
Promise.prototype.finally(onFinally) | ES2018 | ✔ |
Promise.resolve(value) | ES2015 | ✔ |
Promise.reject(reason) | ES2015 | ✔ |
Promise.all(iterable) | ES2015 | ✔ |
Promise.race(iterable) | ES2015 | ✔ |
Promise.allSettled(iterable) | ES2020 | ✔ |
Promise.any(iterable) | ES2021 | ✔ |
npm i -S promise-for-es
// ES Module
import 'promise-for-es/polyfill';
// CommonJS
require('promise-for-es/polyfill');
// ES Module
import Promise from 'promise-for-es';
// CommonJS
const Promise = require('promise-for-es');
Using the example below:
const executor = (resolutionFunc, rejectionFunc) => {
// business logic
};
const p1 = new Promise(executor);
p1.then(onFulfilled, onRejected);
p2
;p1
:
onFulfilled
into the fulfill list of p1
, and push onRejected
into the reject list;onFulfilled
, p2
and the result of p1
;onRejected
, p2
and the result of p1
;p2
;resolutionFunc
, rejectionFunc
;executor
with resolutionFunc
and rejectionFunc
as the arguments;value
is thenable, create a micro task with value
, return;p1
to "fulfilled";p1
to "rejected";npm run test:aplus
to run Promises/A+ compliance test;npm run test:es6
to run promises-es6-tests;npm run test:core-js
to run the core-js tests about Promise;此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。