SOURCE

function LazyMan(name){
    this.name = name;  
    console.log(this.name)
}

LazyMan.prototype.eat = function(item){
    this.chain = this.chain.then(()=> new Promise(resolve=>{
        console.log(item);
        resolve();
    }))
    return this;
}

LazyMan.prototype.sleep = function(time){  
    this.chain = this.chain.then(()=> new Promise(resolve=>{
        setTimeout(()=>{
        resolve()
        console.log(time)
        },time*1000)
    }))
    return this;
}

LazyMan.prototype.chain = Promise.resolve();

let a = new LazyMan('Jack');
a.eat('lunch').sleep(1).eat('dinner')
console 命令行工具 X clear

                    
>
console