+4  A: 

Setting properties on the window object is equivalent to creating global variables. That is, sometimes doing it is inevitable, but you should try to keep it to a bare minimum, as it ends up polluting the global namespace.

In your case, creating a single property is not so bad. If you want to be extra careful about it, you can explicitly create a namespace for any stuff you need global access to:

// In init:
var mynamespace = {};

. . .

// Once the controller is available:
var namespace = window.mynamespace;
namespace.controller = controller;
namespace.foo = bar; // Set other stuff here as well.
levik
Thanks. For some reason I hadn't thought to use a namespace, even though I'm using one elsewhere.
John Topley
+1  A: 

I would say it's bad practice. You can always, and easily, create a namespace for your application and put globals in there, if you must.

hvgotcodes
+1  A: 

They are useful when you want to call a global function whose name is not known beforehand.

var funcName = "updateAns" + ansNum;
window[funcName]();

They can be used to a) avoid evil evals in most cases. b) avoid reference errors to global variables.

x = x + 1 will generate a reference error if a global x is not defined. window.x = window.x + 1 will not

letronje