Tengo una clase llamada Timer:
class Timer { #tick() { console.error('Error usage of interface Timer explicitly deleted'); } startTimer() { console.error('Error usage of interface Timer explicitly deleted'); } }Y tengo una clase llamada CyclingTimer que se deriva de Timer:
class CyclingTimer extends Timer { #maximumTime #timeBetweenTicks #currentTime #onTick constructor(maximumTime, timeBetweenTicks) { super(); this.#maximumTime = maximumTime; this.#timeBetweenTicks = timeBetweenTicks; this.#currentTime = 1; } #validateBoundaries() { if(this.#currentTime > this.#maximumTime) this.#currentTime = 1; else if(this.#currentTime < 1) this.#currentTime = this.#maximumTime; } #tick() { //I console.log(this) here to debug and it printed the Window object as this. I don't know why this.#currentTime++; //Error Occures In This Line this.#validateBoundaries(); this.#onTick(); } startTimer() { //When I console.log(this) here it prints CyclingTimer as expected setInterval(this.#tick, this.#timeBetweenTicks); } setOnTickFunction(callbackFunction) { this.#onTick = callbackFunction; } }No tengo idea de por qué sucede esto y estas son las únicas cosas que tengo. Cuando busqué sobre el error no encontré nada.
Finalmente resolví el problema. El problema fue cuando al usar setInterval() 'tick()' perdí su 'esto' para resolver este problema, vinculo 'tick()' a mi objeto que pasar la función enlazada a setInterval()