Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2: Do not overwrite this.routes in #_bindRoutes #3633

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 4 additions & 5 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -1477,11 +1477,10 @@
// order of the routes here to support behavior where the most general
// routes can be defined at the bottom of the route map.
_bindRoutes: function() {
if (!this.routes) return;
this.routes = _.result(this, 'routes');
var route, routes = _.keys(this.routes);
while ((route = routes.pop()) != null) {
this.route(route, this.routes[route]);
var routes = _.result(this, 'routes');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if routes is undefined. I would highly suggest using _.each here TBH as it will support undefined

var keys = _.keys(routes);
for (var i = keys.length - 1; i >= 0; i--) {
this.route(keys[i], routes[keys[i]]);
}
},

Expand Down
2 changes: 1 addition & 1 deletion test/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@
});

var router = new RouterExtended();
deepEqual({home: "root", index: "index.html", show: "show", search: "search"}, router.routes);
deepEqual({home: "root", index: "index.html", show: "show", search: "search"}, router.routes());
});

test("#2538 - hashChange to pushState only if both requested.", 0, function() {
Expand Down