Merge pull request #1008 from braddunbar/missing-callback

`on` is a noop if no callback is provided
This commit is contained in:
Jeremy Ashkenas
2012-02-14 12:29:38 -08:00
2 changed files with 5 additions and 0 deletions

View File

@@ -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()) {

View File

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