title: Is setting properties on the Window object considered bad practice?
body: <p>I'm writing a quite complex JavaScript application that has an MVC architecture that I'm implementing using Prototype's <a href="http://www.prototypejs.org/api/class" rel="noreferrer"><code>Class</code></a> support and the Module pattern. The application uses AJAX and the Observer pattern. I create my controller instance when the DOM has loaded, pass it a view and some models created from JSON data and away it goes. </p>
  
  <p>However, I've found that I have to set my controller instance as a property on the <code>Window</code> object&mdash;i.e. declare it without using <code>var</code>&mdash;because I have an AJAX success callback that refreshes the view object owned by the controller and at this point in the code my nice little MVC world is not in scope.</p>
  
  <p>I investigated passing in the view object as a parameter to the function containing the AJAX code, but this got really messy and would have led to some horrible violations of the MVC pattern, such as coupling the model and the view. It was horrendous.</p>
  
  <p>Is doing things like storing my controller instance directly on <code>Window</code> considered bad form? It smells a bit like using a global variable to me, but I can't see any way around it.</p>