Marionette.EventBinder ====================== The ``EventBinder`` object provides event binding management for related events, across any number of objects that trigger the events. This allows events to be grouped together and unbound with a single call during the clean-up of an object that is bound to the events. Documentation Index ------------------- - `Bind Events <#bind-events>`_ - `Unbind A Single Event <#unbind-a-single-event>`_ - `Unbind All Events <#unbind-all-events>`_ - `When To Use EventBinder vs ``on`` Handlers <#when-to-use-eventbinder-vs-on-handlers>`_ Bind Events ----------- \`\`\`js var binder = new Backbone.Marionette.EventBinder(); var model = new MyModel(); var handler = { doIt: function(){} } binder.bindTo(model, "change:foo", handler.doIt); \`\`\` You can optionally specify a 4th parameter as the context in which the callback method for the event will be executed: ``js binder.bindTo(model, "change:foo", someCallback, someContext);`` Unbind A Single Event --------------------- When you call ``bindTo``, it returns a "binding" object that can be used to unbind from a single event with the ``unbindFrom`` method: \`\`\`js var binding = binder.bindTo(model, "change:foo", someCallback, someContext); // later in the code binder.unbindFrom(binding); \`\`\` This will unbind the event that was configured with the binding object, and remove it from the EventBinder bindings. Unbind All Events ----------------- You can call ``unbindAll`` to unbind all events that were bound with the ``bindTo`` method: ``js binder.unbindAll();`` This even works with in-line callback functions. When To Use EventBinder vs ``on`` Handlers ------------------------------------------ See the wiki: `When to use the EventBinder `_