Skip to content
Permalink
Browse files

`off` is chainable when there are no events.

  • Loading branch information...
braddunbar committed Apr 4, 2012
1 parent a2ed079 commit af30bcf3ca60c4234df099762344ff4b479260e7
Showing with 13 additions and 1 deletion.
  1. +1 −1 backbone.js
  2. +12 −0 test/events.js
@@ -116,7 +116,7 @@
var event, calls, node, tail, cb, ctx;

// No events, or removing *all* events.
if (!(calls = this._callbacks)) return;
if (!(calls = this._callbacks)) return this;
if (!(events || callback || context)) {
delete this._callbacks;
return this;
@@ -167,4 +167,16 @@ $(document).ready(function() {
obj.trigger('x y');
});

test("off is chainable", function() {
var obj = _.extend({}, Backbone.Events);
// With no events
ok(obj.off() === obj);
// When removing all events
obj.on('event', function(){}, obj);
ok(obj.off() === obj);
// When removing some events
obj.on('event', function(){}, obj);
ok(obj.off('event') === obj);
});

});

0 comments on commit af30bcf

Please sign in to comment.
You can’t perform that action at this time.