Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

306
Views
Uncaught TypeError: can't set private field: object is not the right class

I have a class called Timer:

class Timer {
  #tick() {
    console.error('Error usage of interface Timer explicitly deleted');
  }

  startTimer() {
    console.error('Error usage of interface Timer explicitly deleted');
  }
}

And I have a class called CyclingTimer which derives from 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;
  }
}

I have no clue why this happens and these are the only things I have. When I searched about the error I found nothing.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I finally solved the issue. The problem was when using setInterval() 'tick()' lost its 'this' to solve this issue I bind 'tick()' to my object than pass binded function to setInterval()

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!