Skip to content

Instantly share code, notes, and snippets.

@alexstone
Created April 9, 2018 15:53
Show Gist options
  • Save alexstone/efe2f7f482b29e3891805172b50584cd to your computer and use it in GitHub Desktop.
Save alexstone/efe2f7f482b29e3891805172b50584cd to your computer and use it in GitHub Desktop.
Function for delaying input from a user to prevent firing events on every keyUp
var delay = (function(){
var timer = 0;
return function(callback, ms) { clearTimeout (timer); timer = setTimeout(callback, ms); };
})();
@alexstone
Copy link
Author

Used like this:

delay(function() { doSomething(); }.bind(this), 1000);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment