es6-promise-polyfill
umd
模块规范,支持node
,浏览器或者直接引用js
使用PromisePolyfill
全局变量。
安装
npm install --save es-promise-polyfill
# or
yarn add es-promise-polyfill
使用
- es module
import Promise from 'es-promise-polyfill'
// 跟es6语法使用方法一样
new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 1000);
}).then(res => {
console.log(res);
});
- commonJS
const Promise = require('es-promise-polyfill');
// 跟es6语法使用方法一样
new Promise((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 1000);
}).then(res => {
console.log(res);
});
- 非模块化环境
下载lib/index.min.js,然后在script标签引用。
<script src="your path to save index.min.js"></script>
// 使用全局变量 PromisePolyfill,然后跟es6语法使用方法一样
new PromisePolyfill((resolve, reject) => {
setTimeout(() => {
resolve(true);
}, 1000);
}).then(res => {
console.log(res);
});