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();
});
I’m guessing that you’re using an old version of Backbone, something pre-0.5.0.
Backbone.Routerused to be calledBackbone.Controllerbut it was renamed as part of 0.5.0: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.