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

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

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