Skip to content

Instantly share code, notes, and snippets.

@srph
Last active December 20, 2016 14:09
Show Gist options
  • Select an option

  • Save srph/26fb780b84d6e1f183cd4749231172ba to your computer and use it in GitHub Desktop.

Select an option

Save srph/26fb780b84d6e1f183cd4749231172ba to your computer and use it in GitHub Desktop.
JS: Throttle
function throttle(cb, ms) {
var flag = false;
return function() {
var context = this;
var args = arguments;
if ( flag ) {
return;
}
flag = true;
cb.apply(context, args);
setTimeout(function() {
flag = false;
}, ms);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment