Skip to content

Instantly share code, notes, and snippets.

@edwinvdgraaf
Created August 25, 2012 17:25
Show Gist options
  • Save edwinvdgraaf/3468168 to your computer and use it in GitHub Desktop.
Save edwinvdgraaf/3468168 to your computer and use it in GitHub Desktop.
var throttle = function(fn, delay) {
delay || (delay = 100);
var throttle = false;
return function(){
if (throttle){ return; } // you no enter
throttle = setTimeout(function(){
// tail it - and do one last ajax request
fn.apply(this, arguments);
throttle = false;
}, delay);
fn.apply(this, arguments);
};
};
field.on("keyup", throttle(keyUpFn.bind(this), 2000));
@podgorniy
Copy link

This is beautiful simplicity I needed. Thanks for capturing this solution.

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