SOURCE

class LazyMan{
    constructor(name) {
        this.name = name;
        this.queue = [];
        console.log(this.name)
        // return name;
    }
    eat(food) {
        const fn = () => {
            console.log(food)
        }
        this.queue.push(fn)
        this.next()
        return this;
    }
    sleep(time) {
        const fn = () => {
            setTimeout(() => {
                console.log('sleep')
                this.next()
            }, time)
        }
        this.queue.push(fn)
        return this;
    }
    next() {
        const fn = this.queue.shift();
        fn && fn();
    }
}   

function lazyMan(name) {
    return new LazyMan(name);
}

lazyMan('tony').sleep(3000).eat('aaa');
console 命令行工具 X clear

                    
>
console