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

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

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 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