for (var i = 0; i < friends.length; i++) {
var friend = $("<li>" + friends[i].name + "</li>");
FB.api('/' + eventId + '/invited/' + friends[i].id, 'post', {}, function (response) {
//friend here is the last one created for all callbacks
});
}
I have a loop which invites friends to an event, I am finding the the jquery friend object created here is always the last one created for all callbacks. I am assuming this is because the Facebook call is asynchronous. How would I be able to maintain scope here?
Try this: