Last active
August 29, 2015 14:20
-
-
Save navio/8c4d50575edc2c82dd26 to your computer and use it in GitHub Desktop.
Debounce Example
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(){ | |
var debounce = function(fn,time){ | |
var status = true; | |
var timer = setTimeout(updateTimer(),time); | |
function updateTimer(){ | |
status = true; | |
} | |
return function(){ | |
if(status){ | |
fn.apply(this,params); status = false; | |
}else{ | |
clearTimeout(timer); | |
} | |
}; | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment