נעבור לאנגלית:
// this is bad: // same item is passed to the callback because it's by reference // outcome: only "George" will be dealt with 3 times var arr = ["AVI", "Benz", "George"]; for (var i=0; i < arr.length; i++) { var item = arr[i]; api.do_something(function(result) { callback(result,item); }); } // this is the correct way: // using a self invoked function // item is copied every iteration into the callback as param var arr = ["AVI", "Benz", "George"]; for (var i=0; i < arr.length; i++) { var item = arr[i]; (function(item) { api.do_something(function(result) { callback(result,item); }); })(item); }