my-promise
├─ LICENSE
├─ README.md
├─ my-promise.js ..................... 手写代码
├─ package-lock.json
├─ package.json ...................... npm run test 运行 Promise A+ test
└─ test.js ........................... 面试题测试
- 安装一下
npm install promises-aplus-tests -D
- 手写代码中加入 deferred
MyPromise {
......
}
MyPromise.deferred = function () {
var result = {};
result.promise = new MyPromise(function (resolve, reject) {
result.resolve = resolve;
result.reject = reject;
});
return result;
}
module.exports = MyPromise;
- 配置启动命令
// package.json
"scripts": {
"test": "promises-aplus-tests my-promise"
},
开启测试
npm run test