Skip to content

Commit

Permalink
Merge pull request #1008 from braddunbar/missing-callback
Browse files Browse the repository at this point in the history
`on` is a noop if no callback is provided
  • Loading branch information
jashkenas committed Feb 14, 2012
2 parents b9e36f0 + 8b285c6 commit 04e2e20
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions backbone.js
Expand Up @@ -86,6 +86,7 @@
// function. Passing `"all"` will bind the callback to all events fired.
on: function(events, callback, context) {
var ev;
if (!callback) return this;
events = events.split(/\s+/);
var calls = this._callbacks || (this._callbacks = {});
while (ev = events.shift()) {
Expand Down
4 changes: 4 additions & 0 deletions test/events.js
Expand Up @@ -145,4 +145,8 @@ $(document).ready(function() {
equal(counter, 2, 'unbind does not alter callback list');
});

test("if no callback is provided, `on` is a noop", function() {
_.extend({}, Backbone.Events).bind('test').trigger('test');
});

});

0 comments on commit 04e2e20

Please sign in to comment.