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…
- If I define a router with multiple routes, is the
initializefunction called each time one of those routes is called with a call torouter.navigate?? - What would be the most appropriate way to delay the execution of a route handler until after initialization has occurred?
Thanks.
Think of
initializefunction asconstructorfunction you would normally find in other OOP languages or OOP concepts. Whenever you create a new instance, theinitializefunction is called. Hence you can put up any initialization code, settings or defaults, etc in that.You don’t need to worry about it, backbone will fire the event at the appropriate time.
Just keep in mind that
initializeis called only when you create a new instance of the class. usingnewkeyword.