Skip to content

Instantly share code, notes, and snippets.

@benshimmin
Created July 23, 2013 14:31
Show Gist options
  • Save benshimmin/6062806 to your computer and use it in GitHub Desktop.
Save benshimmin/6062806 to your computer and use it in GitHub Desktop.
Throttle a click event *and* prevent default action with Underscore and Backbone
var View = Backbone.View.extend({
events : function() {
var events = {};
var throttledAction = _.throttle(this.doSomeAction, 500);
events["click .someItem"] = function(event) {
throttledAction.call(this, event);
event.preventDefault();
};
return events;
},
doSomeAction : function(event) { ... }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment