这是我的代码。我基本上想在 getFollows 函数中返回“body”变量。设置变量显然不起作用,不知道如何获取变量。我无法更改 getUserFollowedChannels 因为它是一个包,并且由于 meteor 服务器->客户端的内容,我需要将其直接返回到函数。
'twitch.getFollows'() {
var followers = twitch.getUserFollowedChannels('atlatonin', function(err, body) {
if (err) {
return err;
} else {
console.log(body.follows[0].channel.display_name);
return body.follows[0].channel.display_name;
}
});
return followers;
},
最佳答案
您可以传递回调函数,如下所示:
'twitch.getFollows': function(done) {
twitch.getUserFollowedChannels('atlatonin', done);
}
并调用如下函数:
twitch.getFollows(function(err, body) {
if (err) {
console.log(err);
//return err;
} else {
console.log(body.follows[0].channel.display_name);
//return body.follows[0].channel.display_name;
}
});
关于javascript - 返回一个内部有回调的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38194734/