Skip to content

Instantly share code, notes, and snippets.

@olimortimer
Created November 7, 2013 12:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olimortimer/7353538 to your computer and use it in GitHub Desktop.
Save olimortimer/7353538 to your computer and use it in GitHub Desktop.
JS: Delay
var delay = (function() {
var timer = 0;
return function(callback, ms) {
clearTimeout(timer);
timer = setTimeout(callback, ms);
};
})();
// Set a delay before doing something else - ie, wait until they've stopped typing
delay(function() {
console.log('Done!');
}, 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment