Backbone extends Events

This commit is contained in:
Casey Foster
2012-12-10 07:46:00 -08:00
parent 7dbfecc6c1
commit a3da45efd5
2 changed files with 12 additions and 0 deletions

View File

@@ -205,6 +205,9 @@
Events.bind = Events.on;
Events.unbind = Events.off;
// Supply a global event emitter on Backbone itself.
_.extend(Backbone, Events);
// Backbone.Model
// --------------

View File

@@ -298,4 +298,13 @@ $(document).ready(function() {
equal(obj.counter, 3);
});
test("the Backbone object can on/once/off/trigger", 2, function() {
Backbone.on('event', function() { ok(true); });
Backbone.once('other-event', function() { ok(true); });
Backbone.trigger('event');
Backbone.trigger('other-event');
Backbone.off('event');
Backbone.trigger('event');
});
});