从回调函数中获取变量

时间:2015-02-14 18:59:20

标签: javascript asynchronous callback scope

所以我有一个调用回调函数。它在另一个函数中

function otherFunction() {

    getUserStatus(function(status) {
        console.log(status);
    });
}

函数getUserStatus()执行我想要的所有处理,console.log()显示正确的变量。

但是我似乎无法访问回调函数范围之外的变量。我想在otherFunction()

中访问它

我尝试使用otherFunction()var status;在回调函数之外创建一个变量(在var otherstatus;内部),并为这些变量分配状态,但是将它们分配给我的想法将是范围内的变量也不起作用。

那么如何将这个变量放到函数的范围内呢?

0 个答案:

没有答案
相关问题