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

135
Views
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 answers
Answer question

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