Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.