-
-
Save mattosborn/eac461aeacacca3bd0c9 to your computer and use it in GitHub Desktop.
Debounce
This file contains 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(fn, interval) { | |
var lastCall; | |
return function() { | |
var now = Date.now(); | |
if(!lastCall || now - lastCall > interval) { | |
fn.apply(this, arguments); | |
lastCall = now; | |
} | |
}; | |
} |
This file contains 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 hello() { | |
return console.log('hello world'); | |
} | |
setInterval(debounce(hello, 2000), 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment