// executor function(resolve, reject) {...} );
const PENDING = 'pending'
const RESOLVED = 'resolved'
const REJECTED = 'rejected'
function MyPromise(executor) {
status=PENDING;
callbacks = [];
function resolve(val) {
debugger;
this.callbacks[0](val);
}
function reject(reason) {
}
executor(resolve, reject);
}
MyPromise.prototype.then = (onResolve, onReReject) => {
this.callbacks.push(onResolve)
}
var p = new MyPromise(
function (res, rej) {
debugger
console.log('1');
setTimeout(() => {
debugger
console.log('a')
res('ok')
}, 1000);
}
);
p.then((val) => {
console.log(val)
})
相关文章
- 04-10promise
- 04-10ES6 - Note5:Promise
- 04-10浅谈angular中的promise
- 04-10uniapp封装promise图片上传方法(ts版,js的话把参数类型去掉就行)
- 04-10promise.all使用
- 04-10Promise
- 04-10把ajax包装成promise的形式
- 04-10Promise和callback获取异步处理函数的结果
- 04-10es6(13)--Promise
- 04-10Promise