promise

//  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)
})

上一篇:JavaScript调试


下一篇:fiddler替换修改后的js文件绕过无限debugger