off is chainable when there are no events.

This commit is contained in:
Brad Dunbar
2012-04-04 05:52:54 -07:00
parent a2ed079af8
commit af30bcf3ca
2 changed files with 13 additions and 1 deletions

View File

@@ -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;

View File

@@ -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);
});
});