Skip to content

Instantly share code, notes, and snippets.

@jimitit
Forked from luan0ap/debounce.js
Created July 20, 2018 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimitit/a361b7a3e4611781d8c2d5af4f359bdb to your computer and use it in GitHub Desktop.
Save jimitit/a361b7a3e4611781d8c2d5af4f359bdb to your computer and use it in GitHub Desktop.
Implement a job scheduler which takes in a function f and an integer n, and calls f after n milliseconds.
const debounce = (fn = () => {}, wait = 1000) => (...args) => {
const delayed = () => fn.apply(this, args)
return setTimeout(delayed, wait)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment