Skip to content

Instantly share code, notes, and snippets.

@ottonascarella
Created June 26, 2016 06:10
Show Gist options
  • Save ottonascarella/acdf36df33b4f911297d6be1d91e2d67 to your computer and use it in GitHub Desktop.
Save ottonascarella/acdf36df33b4f911297d6be1d91e2d67 to your computer and use it in GitHub Desktop.
Function throttling Vanilla JS
Function.prototype.throttle = function(delay) {
var outter = this,
timer, control = false;
return function() {
if (control) return;
control = true;
var inner = this,
args = [].slice.apply(arguments);
clearTimeout(timer);
timer = setTimeout(function() {
control = false;
outter.apply(inner, args);
}, delay);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment