I'm trying to pass current value to callback function. I used this answers to work with, but it doesn't work for me.
for (var i = 0; i < 4; i++) {
(function(_i) {
var options = {
//Options here
};
console.log(_i); // 0, 1, 2, 3
LocalImageManager.download(options, function (results, _i) {
console.log(_i); //undefined, undefined, undefined, undefined
//Do stuff with results
});
}
})(i);
The problem is function always works with "i" variable, which is undefined after the loop finished.