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

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

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