From 3d431346c74cf7597bde93109d88889de861b005 Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Wed, 20 Mar 2013 01:42:29 -0400 Subject: [PATCH] Use empty route name for anonymous routes. --- backbone.js | 6 +++++- test/router.js | 5 ++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backbone.js b/backbone.js index 3e37c231f..ab2506fdc 100644 --- a/backbone.js +++ b/backbone.js @@ -981,7 +981,11 @@ // route: function(route, name, callback) { if (!_.isRegExp(route)) route = this._routeToRegExp(route); - if (!callback) callback = _.isFunction(name) ? name : this[name]; + if (_.isFunction(name)) { + callback = name; + name = ''; + } + if (!callback) callback = this[name]; var router = this; Backbone.history.route(route, function(fragment) { var args = router._extractParameters(route, fragment); diff --git a/test/router.js b/test/router.js index e0c86c2cf..e6e1b3d6e 100644 --- a/test/router.js +++ b/test/router.js @@ -286,7 +286,10 @@ $(document).ready(function() { equal(router.anything, 'doesnt-match-a-route'); }); - test("routes (function)", 2, function() { + test("routes (function)", 3, function() { + router.on('route', function(name) { + ok(name === ''); + }); equal(ExternalObject.value, 'unset'); location.replace('http://example.com#function/set'); Backbone.history.checkUrl();