Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

233
Visualizações
(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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda