SOURCE

class LazyMan{
    constructor(name){
        this.name = name;
        this.task = [];

        console.log('I am Jack');
        setTimeout(()=>{
            this.next()
        })
    }
    eat(food){
        this.task.push(()=>{
            console.log('eat ' + food)
        })
        return this
    }
    sleep(time){
        this.task.push(()=>{
            setTimeout(()=>{
                console.log(time);
                this.next()
            },time*1000)
        })
        return this
    }

    next(){
        let fn = this.task.shift();
        fn && fn()
    }
}
const lazyMan = new LazyMan('Jack')
lazyMan.eat('lunch').sleep(1).eat('dinner')
console 命令行工具 X clear

                    
>
console