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

231
Views
(Typescript/Javascript) setInterval method can't call other functions

I want to call the function callMe() every 1000 ms. This works so far, but I cannot call another function out of callMe(). I get the following Error:

uncaught TypeError: this.sortTargets is not a function

My class variable:

private intervalId : any;

The code/functions

constructor () {
    this.intervalId = setInterval(this.checkLabelConflicts, 1000);
  }

  private sortTargets() {
    console.log("hello world");
  }

  private checkFunction()  {
  this.sortTargets();
}

Why am I not able to call other functions out of the intervaled function? I already tried to set the constructor to bottom of the code, it feels like this is a declaration missing error. If someone has another solution without setInterval (e.g. workers/threads?) you're welcome to explain it to me.

Happy monday

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

0

How to access the correct `this` inside a callback

constructor () {
    this.intervalId = setInterval(this.checkLabelConflicts.bind(this), 1000);
  }

  private sortTargets() {
    console.log("hello world");
  }

  private checkFunction()  {
  this.sortTargets();
}

I had to .bind(this)

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!