Last active
August 29, 2015 14:15
-
-
Save u01jmg3/603d0e3fbc86678878cd to your computer and use it in GitHub Desktop.
Delays when a function runs. Perfect for using with a search box and waiting for a user to finish typing a term before executing a filter script.
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
/** | |
* Delays when a function runs. | |
* | |
* @return callback | |
*/ | |
var delay = (function(){ | |
var timer = 0; | |
return function(callback, ms){ | |
clearTimeout(timer); | |
timer = setTimeout(callback, ms); | |
}; | |
})(); | |
//delay(function(){console.log('Hello World!')}, 100); //milliseconds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment