DEV Community

Discussion on: Ever heard of debouncing in in javascript , What is it ?

Collapse
 
lexlohr profile image
Alex Lohr

It's a bit more straight forward in modern JavaScript:

const debounce = (fn, delay) => {
  let timer
  return (...args) => {
    clearTimeout(timer)
    timer = setTimeout(() => fn(...args), delay)
  }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
ashishjshetty profile image
Ashish J shetty

thank you , this looks simpler.