Here's another variation on the technique, similar to Bjorn's (apphacker), which lets you assign the variable value inside the function rather than passing it as a parameter, which might be clearer sometimes:
var funcs = [];_x000D_
for (var i = 0; i < 3; i++) {_x000D_
funcs[i] = (function() {_x000D_
var index = i;_x000D_
return function() {_x000D_
console.log("My value: " + index);_x000D_
}_x000D_
})();_x000D_
}
_x000D_
Note that whatever technique you use, the index
variable becomes a sort of static variable, bound to the returned copy of the inner function. I.e., changes to its value are preserved between calls. It can be very handy.