简体   繁体   English

在JavaScript中声明全局变量

[英]declaring global variable in javascript

So I have the following code: 所以我有以下代码:

window.fbAsyncInit = function() {
  FB.init({appId: appID, xfbml: true, status: true, cookie: true});
}   

...some lines of code

function anotherFunction()
{
    FB.ui(blah,blah);
}

FB.ui throws me a ReferenceError:FB is not defined . FB.ui向我抛出ReferenceError:FB is not defined This wasnt happening before I wrapped FB.init inside window.fbAsyncInit , which I have to in order to init FB correctly. 在将FB.init包装在window.fbAsyncInit ,这并没有发生,为了正确地初始化FB,我必须这样做。 How can I make FB get recognized inside anotherFunction ? 如何使FB在anotherFunction被识别?

FB is the facebook library. FB是facebook库。 The init function is supposed to initialize and set it globally. 应该使用init函数初始化并全局设置它。 The var FB; var FB; line wasnt there initially. 最初没有在那里。 I only added it to check if that will remove the error, because the error was already there 我只添加了它来检查是否可以消除错误,因为错误已经存在

Any pointers are greatly appreciated! 任何指针,不胜感激!

Don't you need to initialize the variable somehow ? 您不需要以某种方式初始化变量吗? You seem to be calling 'init' on a null value... 您似乎在对空值调用'init'...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM