Skip to content

Instantly share code, notes, and snippets.



Created Nov 21, 2012
What would you like to do?
// Based on
// Bind an event like `on`, but unbind the event following the first trigger.
window.Backbone.Model.prototype.once =
window.Backbone.View.prototype.once =
window.Backbone.Events.once = function (events, callback, context) {
  // Bind the original events.
  this.on(events, callback, context);
  // Bind a new event immediately preceeding the original to unbind the original once called.
  this.on(events, function unbind() {
    // Remove the original event and the cleanup event., callback, context).off(events, unbind);
  }, this);
  return this;
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.