The difference is the constructor
. Backbone classes all have a method which gets run when you instantiate the class. That constructor
method is how your initialize
method gets called when you do new Backbone.Router()
.
As you can see in, the constructor
for Router
:
var Router = Backbone.Router = function(options) {
options || (options = {});
if (options.routes) this.routes = options.routes;
this._bindRoutes();
this.initialize.apply(this, arguments);
};
the main difference between calling initialize
and instantiating a router is that when you instantiate it the routes are bound.
Well, that's the main Backbone difference. There's also the Javascript difference between calling new A.B()
and A.B()
, which is that the new
keyword creates a new object and sets it as the this
inside your constructor
/initialize
function, whereas calling it directly the way you're doing sets this
to the Router
class itself.
Because you almost certainly don't want to be using your Router
class as the this
when you test your methods, what you likely want to do is just instantiate a Rotuer
properly in your setup code.