Reputation:
i am getting an error in this code at first line plz help me Cannot call method 'extend' of undefined
$(document).ready(function() {
var Router = Backbone.Router.extend({
routes: {
"foo/:bar": "paramtest",
"*action": "func"
},
func: function(action) {
alert(action);
},
paramtest: function(p) {
alert(p);
}
});
new Router();
Backbone.history.start();
});
Upvotes: 1
Views: 2258
Reputation: 265
In your HTML file make sure you declare your underscore js file before your backbone js file.
Upvotes: 4
Reputation: 434606
I'm guessing that you're using an old version of Backbone, something pre-0.5.0. Backbone.Router
used to be called Backbone.Controller
but it was renamed as part of 0.5.0:
0.5.0 — July 1, 2011
[...]
Controller
was renamed toRouter
, for clarity.
The second Google hit for "backbone tutorial" points me at this tutorial which uses 0.3.3. There seems to be a lot of people using 0.3.3 asking questions about Backbone lately so the Google results are probably the problem.
You should upgrade to the latest version (0.9.2) of Backbone, you can get it from the Backbone website. You should probably be using the latest version of Underscore (1.4.2) as well, you can get that at the Underscore website.
Upvotes: 2
Reputation: 490153
For some reason your Backbone object does not have the Router
property on it. Are you overwriting it somewhere?
Upvotes: 0