Hello.
Closures are a very powerful tool, but you need to use them with some alertness =)
The point is that in your example, all created functions have access to the variable i from the scope of the parent function. To the same variable i and when accessing it, its value is obtained at the time of the call.
In order to overcome this behavior, all you need is to fix the value of i at the time of creating the callback function. This can be achieved by adding a temporary function to the code, which will save the current value i in its scope and return a handler function, which, in turn, will have access to the value i fixed in the scope of the parent temporary function
Something like this.
var i; for(i in many_i) { image[i].onload = (function(){ var closedI = i; return function (e) { console.log(closedI, e); } })() }
More available topic is disclosed here.