Skip to content

Instantly share code, notes, and snippets.

@griffinmichl
Last active March 26, 2019 14:11
Show Gist options
  • Select an option

  • Save griffinmichl/72aaab6289780494dc85f88bf4528971 to your computer and use it in GitHub Desktop.

Select an option

Save griffinmichl/72aaab6289780494dc85f88bf4528971 to your computer and use it in GitHub Desktop.
function debounce(func, wait) {
let timeout
return function(...args) {
const context = this
clearTimeout(timeout)
timeout = setTimeout(() => func.apply(context, args), wait)
}
}
function sayHello() {
console.log('My name is', this.name)
}
const amy = {
name: 'amy',
speak: debounce(sayHello),
}
amy.speak()
// 'My name is amy'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment