javascript - Function return async response -
this question has answer here:
- how return response asynchronous call? 21 answers
like person asked here (but solutions call nother function) https://stackoverflow.com/a/10796326/315200 ...i know if possible have function doesn't call second function on response of async request, return
when async request responses.
something maybe:
function calltofacebook() { var fbresponse; fb.api('/me', function (response) { fbresponse = response; }); return fbresponse; //will return undefined because calltofacebook async }
isn't possible way, without calling function??
what i'm trying achieve have 1 function can call parameters, return response object
async webservice, fb.
in short, no. cannot have asynchronous function return meaningful value synchronously, because value not exist @ time (as built asynchronously in background).
you can, however, return promise object, representing "potential return value" of asynchronous operation, , bind function object using done() or similar. way, function gets return semantics (instead of having chain control flow callback), , remains asynchronous.
Comments
Post a Comment