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

171
Vistas
Can't I use the arrow function in the debounce function?
export const debounce = (callback: Function, ms = 300) => {
    let timeoutId: ReturnType<typeof setTimeout>
    return function (...args: any[]) {
      clearTimeout(timeoutId)
      timeoutId = setTimeout(() => callback.apply(this, args), ms)
    }
}

I want to make the debounce function a Util function and use it throughout the project. However, if you make the function that the debounce function returns as an arrow function, a script error occurs. This becomes undefined. Can't the function that the debounce function returns use the arrow function? I'm curious about the reason

export const debounce = (callback: Function, ms = 300) => {
    let timeoutId: ReturnType<typeof setTimeout>
    return (...args: any[]) => {
      clearTimeout(timeoutId)
      timeoutId = setTimeout(() => callback.apply(this, args), ms)
    }
}

Changing the arrow function to a returning code in this way causes an error. I'm curious about the reason

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

.this inside arrow function will resolve lexically, meaning that value of this does not depend on call-site(where the function is being called), but instead it depends on the function outer scope(defined when writing code) - basically meaning it will take this lexically from the outer scope (eg: outer function or window object). And that is why there is no sense to use arrow with apply in order to modify this.

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