SOURCE

class Log{
    constructor() {
        this.isWait = false;
        this.waitQu = [];
    }

    log = (value) => {
        if (this.isWait) {
            this.waitQu.push({
                type: 'log',
                value
            });
        } else {
            console.log(value);
        }
        return this;
    }

    sleep = (time) => {
        return new Promise((resolve) => {
            window.setTimeout(() => {
                resolve();
            }, time * 1000);
        });
    }

    executor = async () => {
        if (this.waitQu.length) {
            const item = this.waitQu.shift();
            if (item.type==='log') {
                console.log(item.value);
                this.executor()
            } else if (item.type === 'wait') {
                this.isWait = true;
                await this.sleep(item.value);
                this.isWait = false;
                this.executor();
            }
        }
    }

    wait = (value) => {
        this.waitQu.push({
            type: 'wait',
            value
        });
        if (!this.isWait) {
            this.executor();
        }
        return this;
    }
}

new Log().log(1).wait(5).log(7);
console 命令行工具 X clear

                    
>
console