Skip to content

Instantly share code, notes, and snippets.

@vitalii-komenda
Last active May 6, 2018 01:34
Show Gist options
  • Select an option

  • Save vitalii-komenda/50fc05b09ccecaf0e290 to your computer and use it in GitHub Desktop.

Select an option

Save vitalii-komenda/50fc05b09ccecaf0e290 to your computer and use it in GitHub Desktop.
Throttle helps to save performance, because it reduces number of calls
// It can be used to save input values after change
// $('input').on('change', throttle(function(){
// $.ajax(url);
//}, 1000))
function throttle(fn, time) {
return function inner() {
var args = Array.prototype.slice.call(arguments);
clearTimeout(inner.timeout);
inner.timeout = setTimeout(function () {
fn.apply(null, args);
}, time);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment