SOURCE

class myPromise{
    constructor(fn){

        this.resolveQueue = []
        this.rejectQueue = []
        let _resolve = (resolve) =>{
            for(let fn of this.resolveQueue){
                fn(resolve)
            }
        }
        let _reject = (reject)=>{
            for(let fn of this.resolveQueue){
                fn(reject)
            }
        }
        fn(_resolve,_reject)
    }
    then(resolveFn,rejectFn){
        this.resolveQueue.push(resolveFn)
        this.rejectQueue.push(rejectFn)
    }
}
const p1 = new myPromise((resolve, reject) => {
  setTimeout(() => {
    resolve('result')
  }, 1000);
})
p1.then(res => console.log(res))
//一秒后输出result

console 命令行工具 X clear

                    
>
console