Skip to content

Instantly share code, notes, and snippets.

@pedroteixeira
Created April 24, 2012 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pedroteixeira/2484196 to your computer and use it in GitHub Desktop.
Save pedroteixeira/2484196 to your computer and use it in GitHub Desktop.
Crates buffered function
// 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);
};
};
@bbhoss
Copy link

bbhoss commented May 7, 2012

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

@pedroteixeira
Copy link
Author

thanks for sharing the news

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment