- Building Single:page Web Apps with Meteor
- Fabian Vogelsteller
- 169字
- 2021-08-06 19:29:36
Variable scopes
To understand Meteor's build process and its folder conventions, we need to take a quick look at variable scopes.
Meteor wraps every code files in an anonymous function before serving it. Therefore, declaring a variable with the var
keyword will make it only available in that file's scope, which means these variables can't be accessed in any other file of your app. However, when we declare a variable without this keyword, we make it a globally available variable, which means it can be accessed from any file in our app. To understand this, we can take a look at the following example:
// The following files content var myLocalVariable = 'test'; myGlobalVariable = 'test';
After Meteor's build process, the preceding lines of code will be as follows:
(function(){ var myLocalVariable = 'test'; myGlobalVariable = 'test'; })();
This way, the variable created with var is a local variable of the anonymous function, while the other one can be accessed globally, as it could be created somewhere else before.
- 軟件安全技術(shù)
- TypeScript入門與實(shí)戰(zhàn)
- 自己動(dòng)手寫Java虛擬機(jī)
- 樂學(xué)Web編程:網(wǎng)站制作不神秘
- Functional Kotlin
- Kinect for Windows SDK Programming Guide
- Python機(jī)器學(xué)習(xí)算法與實(shí)戰(zhàn)
- MATLAB 2020從入門到精通
- R語言與網(wǎng)絡(luò)輿情處理
- Cybersecurity Attacks:Red Team Strategies
- 從零開始學(xué)Python網(wǎng)絡(luò)爬蟲
- OpenCV Android Programming By Example
- Python第三方庫開發(fā)應(yīng)用實(shí)戰(zhàn)
- 大規(guī)模語言模型開發(fā)基礎(chǔ)與實(shí)踐
- Python面向?qū)ο缶幊蹋ǖ?版)