我为FB.getLoginStatus
编写了一个包装函数,定义如下:
this.isLoggedInFB = function() {
FB.getLoginStatus(function(response) {
if(response.status == 'connected')
{
return true;
}
else if(response.status =='not_authorized'){
return true;
else{
return false;
}
});
}
每当我发出以下警告
alert(myClass.isLoggedInFB());
我得到undefined
。
当我在isLoggedInFB
正文中添加提醒以查看是否已定义FB
时,我得到:
[Object object]
告诉我它已被调用FB.init
,因此令人困惑
这是我认为唯一可能出错的事情。
最后,我做了一个警告,看看我输错了名称或者我的姓名间距是错误的
alert(myClass.isLoggedInFB);
我得到了正确的函数定义。
答案 0 :(得分:1)
因为函数isLoggedInFB不返回任何值。如果您需要获取响应数据,则需要返回如下值:
var connected = 0;
this.isLoggedInFB = function() {
FB.getLoginStatus(function(response) {
if(response.status == 'connected')
{
connected = 1;
return true;
}
else if(response.status =='not_authorized'){
{
connected = 1;
return true;
}
else{
connected = 0;
return false;
}
});
return connected;
}