Question

I'm pretty new to backbone.js and am still learning how everything works. I'm trying to understand how the initialize option of the backbone router works, and haven't been able to find any good documentation or examples, so I was hoping someone here could help me understand it. I actually have a couple of questions about it...

  1. If I define a router with multiple routes, is the initialize function called each time one of those routes is called with a call to router.navigate??
  2. What would be the most appropriate way to delay the execution of a route handler until after initialization has occurred?

Thanks.

Was it helpful?

Solution

If I define a router with multiple routes, is the initialize function called each time one of those routes is called with a call to router.navigate??

Think of initialize function as constructor function you would normally find in other OOP languages or OOP concepts. Whenever you create a new instance, the initialize function is called. Hence you can put up any initialization code, settings or defaults, etc in that.

What would be the most appropriate way to delay the execution of a route handler until after initialization has occurred?

You don't need to worry about it, backbone will fire the event at the appropriate time.

Just keep in mind that initialize is called only when you create a new instance of the class. using new keyword.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top