Skip to content

Instantly share code, notes, and snippets.

@balanza
Created October 26, 2015 23:34
Show Gist options
  • Select an option

  • Save balanza/8ebebeb4a0310e966f49 to your computer and use it in GitHub Desktop.

Select an option

Save balanza/8ebebeb4a0310e966f49 to your computer and use it in GitHub Desktop.
//click count
var count = 0;
//this is the handler
var onClick = function(e){
alert('button clicked ' + (++count) + ' times');
};
//this is the "throttled" function,
// that is a function that executes only once in a given timespan (here: 200ms)
var throttled = _.throttle(onClick, 200);
//here the handler is bound to the event
document.getElementById("myBtn").addEventListener("click", throttled);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment