From 8b285c6c830d84b39f355c72db3e931fdb785130 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Tue, 14 Feb 2012 15:22:27 -0500 Subject: [PATCH] `on` is a noop if no callback is provided --- backbone.js | 1 + test/events.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/backbone.js b/backbone.js index a8127af0..d10093d6 100644 --- a/backbone.js +++ b/backbone.js @@ -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()) { diff --git a/test/events.js b/test/events.js index bb2aeb05..2c8f3e15 100644 --- a/test/events.js +++ b/test/events.js @@ -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'); + }); + });