Created
August 14, 2012 14:32
-
-
Save dboundz/3349814 to your computer and use it in GitHub Desktop.
Closure question.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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