SOURCE

function myPromise(executor){
    this.PromiseState = 'pendding'
    this.PromiseResult = null
    self = this
    function resolve(data){
        if(self.PromiseState !== 'pendding') return;
        self.PromiseState = 'fulfilled'
        self.PromiseResult = data
    }
    function reject(data){
        if(self.PromiseState !== 'pendding')return;
        self.PromiseState = 'rejected'
        self.PromiseResult = data
    }
       executor(resolve,reject)
}
myPromise.prototype.then = function(onResolved,onRejected){
    if(this.PromiseState === 'rejected'){
        onRejected(this.PromiseResult)
    }
    if(this.PromiseState === 'fulfilled'){
        onResolved(this.PromiseResult)
    }
}
let a = new myPromise((resolve,reject)=>{
    resolve('ok')
    // reject('123')
})
a.then(res=>{
    console.log(res)
},rej=>{
    console.log(rej)
})
console 命令行工具 X clear

                    
>
console