Skip to content

Instantly share code, notes, and snippets.

@icodejs
Created October 28, 2012 08:53
Show Gist options
  • Save icodejs/3968096 to your computer and use it in GitHub Desktop.
Save icodejs/3968096 to your computer and use it in GitHub Desktop.
JS: Throttling function calls
// http://remysharp.com/2010/07/21/throttling-function-calls/
function throttle(fn, delay) {
var timer = null;
return function () {
var context = this, args = arguments;
clearTimeout(timer);
timer = setTimeout(function () {
fn.apply(context, args);
}, delay);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment