Почему этот код работает правильно в консоли, а не на сервере разработки веб-пакетов? - PullRequest
0 голосов
/ 24 сентября 2019

, как гласит заголовок, эта функция хронометра прекрасно работает на консоли и останавливается через 5 секунд, когда я вызываю метод stopChrono(), но на сервере разработки веб-пакетов таймер продолжает работать.Что происходит?

class Timers {
    constructor() {
        this.running = false;
        this.countForward;
    }

    chronometer(seconds) {
        this.seconds = seconds;
        this.date = Date.now();
        this.now = this.date - this.seconds * 1000;

        if (!this.running) {
            this.running = true;
            this.countForward = setInterval(() => {
                this.secondsForward = Math.round((Date.now() - this.now) / 1000);
                console.log(this.secondsForward);
            }, 1000);
            console.dir( this.countForward)
        }
    }

    stopChrono() {
        if (this.running) {
            clearInterval(this.countForward);
            this.running = false;
            console.log('stop')
        }
    }
}

const chrono = new Timers();
chrono.chronometer(0);
setTimeout(() => {
    chrono.stopChrono()
}, 5000);
...