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

344
Views
What should I use instead of `this` inside of nested function or may I use it?

I've class in js - how I can tweak body in nested function in line #4. Im getting warning from IDE:

Potentially invalid reference access to a class field via 'this.' of a nested function

is there any solution to write this properly? Or I can use this inside nested function?

fetchStickyAppointment = flow(function* () {
  fetch(/api/) 
    .then(response => response.json()) 
    .then(data => { 
      if (+data?.id > 0) { 
        this.stickyAppointment = this.currentAppointment = data; 
      } else { 
        this.stickyAppointment = data; 
        this.currentAppointment = this.findCurrentAppointment(); 
      }
    }); 
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could assign this to a variable outside the function scope and then use that.

let self = this;
fetchStickyAppointment = flow(function* () {
  fetch(/api/) 
    .then(response => response.json()) 
    .then(data => { 
      if (+data?.id > 0) { 
        self.stickyAppointment = self.currentAppointment = data; 
      } else { 
        self.stickyAppointment = data; 
        self.currentAppointment = self.findCurrentAppointment(); 
      }
    }); 
})
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!