Last active
March 26, 2019 14:11
-
-
Save griffinmichl/72aaab6289780494dc85f88bf4528971 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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