Skip to content Skip to sidebar Skip to footer

Extract Data From Anonymous Function Scope

Because of the complexity of this application, I have a need to wrap Facebook API calls, like so. //In main file, read is always undefined var read = fb_connect.readStream(); // I

Solution 1:

Judging from your question, it seems that you are looking for a synchronous call. Which means that you'd want to use the data returned from the api call right after calling it. In that case, you'll need to check whether FB.api supports synchronous calls (mostly doesn't).

Otherwise, you'll need to understand that you are making an async call here. Which means that you should put your handling code INSIDE the callback function that you pass to FB.api. This is called the "continuation" style of writing code and is the standard way to use async calls.

FB.api('/me/feed', {limit:10000}, function (response) {
    var stream = response.data;
    // Do your processing here, not outside!!!
});

Or:

function handlerFunction(response) {
   // Do your processing here
}

FB.api('/me/feed', {limit:10000}, handlerFunction);

Post a Comment for "Extract Data From Anonymous Function Scope"