public
Created

Crates buffered function

  • Download Gist
underscore-ext.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
 
// Calls a function only once within the given wait time. Last call is
// considered, which is the difference between from _.throtle
//
_.buffer = function(func, wait, scope) {
var timer = null;
return function() {
if(timer) clearTimeout(timer);
var args = arguments;
timer = setTimeout(function() {
timer = null;
func.apply(scope, args);
}, wait);
};
};

Note, you can use _.debounce for this now.

thanks for sharing the news

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.