Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

236
Vistas
(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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda