-1

window.router = new RouterModel(extended from backbone router)

I can't figure out what its purpose is in an program I'm looking at.

Would I do this to change the router anytime I need to?

fancy
  • 48,619
  • 62
  • 153
  • 231

1 Answers1

2

It assigns an object of RouterModel to the global variable router.

Would I do this to change the router anytime I need to?

Yes, if you want to change the global router variable.

Shef
  • 44,808
  • 15
  • 79
  • 90
  • Is it possible that calling this if you construct a new view when it is initialized would cause every call to grow exponentially? – fancy Sep 11 '11 at 09:43
  • @fancy: By calling this you mean `window.router = new ...`? If that's what you mean, no, you are merely going to assign something else to the variable `router`. – Shef Sep 11 '11 at 09:44
  • I'm facing an issue I think is related to this where logging out/in triggered over and over results in each call growing exponentially until it's calling tons of logout/login functions every time I logout/login. – fancy Sep 11 '11 at 09:45
  • In the router initialization I am building and rendering a new layout views. Do I need to clear other views when I do this or something? – fancy Sep 11 '11 at 09:48
  • @fancy: I am not a whiz in backbone.js, and I am not aware what `RouterModel` does, so I can't comment much on that. If you share the `RouterModel` maybe we can help you with the issue you are facing, but assigning this object to the global variable `router` has nothing to do with what goes on inside `RouterModel`. – Shef Sep 11 '11 at 10:20
  • @fancy - that's a separate issue that has been discussed many times on stackoverflow. some searches should find what you need. – Derick Bailey Sep 11 '11 at 17:00
  • @Derick I can't find any, could you point me to one? Thanks very much. – fancy Sep 12 '11 at 02:06
  • 2
    for example, i answered a similar question here: http://stackoverflow.com/questions/7379263/disposing-of-view-and-model-objects-in-backbone-js/7383008#7383008 ... the question isn't the same, but the cause and solution are – Derick Bailey Sep 12 '11 at 03:29