Closures are logical but subtle and you need to make sure that you really understand them. This is made easier if you think about a closure as a preserved execution context. In this extract from my ...
Understanding the idea of a shared or non-shared execution context can help avoid errors such as: var myFunction = function () { this.f = new Array(5); for (var i = 0; i < 5; i++) { this.f[i] = ...