Backbone Tutorials

On

 

onobject.on(event, callback, [context])Alias: bind

Bind a callback operate to an object. The callback will probably be invoked
at any time when the occasion is fired.
When you have numerous totally different events on a web page, the conference is to make use of colons to
namespace them: "ballot:start", or "change:choice".
The occasion string may be a space-delimited listing of a number of events…

e-book.on("change:title change:writer", ...);

Callbacks sure to the particular
"all" occasion will probably be triggered when any occasion happens, and are handed
the title of the occasion as the primary argument. For instance, to proxy all events
from one object to a different:

proxy.on("all", function(eventName) {
  object.trigger(eventName);
});

All Backbone occasion strategies additionally assist an occasion map syntax, in its place
to positional arguments:

e-book.on(
  "change:author": authorPane.update,
  "change:title change:subtitle": titleView.update,
  "destroy": bookView.remove
);

To produce a context worth for this when the callback is invoked,
go the elective final argument: model.on('change', this.render, this) or
model.on({change: this.render}, this).