[removed] Scope of a Variable across different Javascript files

后端 未结 3 1488
滥情空心
滥情空心 2020-12-16 22:21

I defined a variable in one of my JavaScript files. I want to access the value of that variable among JavaScript files. In one file I am initializing the value of that varia

3条回答
  •  时光说笑
    2020-12-16 22:46

    It has to be a global variable, or accessible in the same scope (e.g. a property on something else that's global), and it has to be defined before you're accessing it, meaning the order of your script includes matters.

    You can't for instance have this in one file:

    (function() {
       var something = "blah";
    })();
    

    ...and access it in the next file, since that variable is scoped to that function.

提交回复
热议问题