weixin_33711641 2012-06-19 10:21 采纳率: 0%
浏览 17

函数返回异步响应[重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call" dir="ltr">How do I return the response from an asynchronous call?</a>
                            <span class="question-originals-answer-count">
                                (38 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2015-10-14 21:35:45Z" class="relativetime">4 years ago</span>.</div>
        </div>
    </aside>

Like a person asked here (but his solutions as to call a nother function) https://stackoverflow.com/a/10796326/315200 ...I would like to know if its possible to have a function which doesn't call a second function on response of an async request, but simply return when the async request responses.

Something like this maybe:

function callToFacebook() {
    var fbResponse;

    FB.api('/me', function (response) {
        fbResponse = response;
    });

    return fbResponse; //Will return undefined because CallToFacebook is async
}

Isn't that possible some way, without calling another function??

What I'm trying to achieve is to have one function I can call with some parameters, which will return the response object from a async webservice, like FB.

</div>
  • 写回答

2条回答 默认 最新

  • weixin_33713707 2012-06-19 10:23
    关注

    No, it's not possible.

    You can't return value that is returned from async operation.

    Think about it, you tell 10 people to have one mile running contest, they start now, will finish in one minute +-, but you want to know the answer now, it's not possible unless you're cheating...

    评论

报告相同问题?

悬赏问题

  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常