passing callbacks using a loop-iteration counter
function create_callback(i){
return function callback(callbackParams) {
// do something with the "right" i
}
}
// create closures with the temporary i and store them for later
var funcs = [];
for (var i = 0; i < 5; i++) {
funcs[i] = create_callback(i);
}
// give the stored closures with encapsulated i as callbacks
for (var j = 0; j < 5; j++) {
giveMeACallback( funcs[j] );
}