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

136
Visualizações
Nested function losing this scope

I have a js script that works fine on its own, however when I try to move my code to reactjs the nested/referenced function loses 'this' and it references window instead. Pseudo code bellow. Any idea what causes this? I figure its related to webpack or something reactjs is doing?

lib.AnMovieClip = function() {
 this.testVariable = true;
 this.gotoAndPlay = function(){
  // 'this' works here perfectly fine
  this.otherFunction();
 }
 this.otherFunction(){
  // returns undefined, as 'this' is now the window object
  console.log(this.testVariable); 
 }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I ended up finding that the value was not being assigned correctly. this.testVariable was being overwritten.

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