SOURCE

class Commitmemt{
    static PENDING = '待定';static FULFILLED = '完成';static REJECT = '拒绝';
    constructor (func){
        this.status = Commitmemt.PENDING;
        this.result = null;
        try{
        func(this.resolve.bind(this),this.resolve.bind(this));
        }
        catch(error){
            this.reject(error)
        }

    }
    resolve(result){
        if(this.status === Commitmemt.PENDING){
            this.status =Commitmemt.FULFILLED;
            this.result = result;
        }
    };
    reject(result){
        if(this.status === Commitmemt.PENDING){
            this.status = Commitmemt.REJECT;
            this.result = result;
        }
    };
    then(onFULFULLED, onREJECT){
        
    }

}

let commitment = new Commitmemt((resolve, reject) => {
    resolve("这次一定");
})

commitment.then(
    result => {console.log(result)},
    result => {console.log(result.message)}
)
console 命令行工具 X clear

                    
>
console