Skip to content

Instantly share code, notes, and snippets.

@dboundz
Created August 14, 2012 14:32
Show Gist options
  • Save dboundz/3349814 to your computer and use it in GitHub Desktop.
Save dboundz/3349814 to your computer and use it in GitHub Desktop.
Closure question.
var get_info = function(list_id, callback) {
// do something and callback with list_info for list_id;
callback(null, list_info);
};
var list = [1,2,3,4,5];
for(var i = 0; i < list.length; i++) {
var list_id = list[i];
get_info(list_id, function (error, list_info) {
// do work on list info and save new data based on list_id;
// problem is list_id is not reliable as it's overwritten by the time we arrive here;
save_info(list_id, new_data, function (error) {});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment