官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 濉溪县| 临夏县| 米脂县| 永嘉县| 芜湖市| 抚宁县| 偏关县| 石屏县| 乐至县| 新安县| 屯留县| 定日县| 江山市| 漳平市| 珠海市| 林西县| 永定县| 建德市| 蒙阴县| 柯坪县| 绥滨县| 兴宁市| 扶绥县| 曲靖市| 秦皇岛市| 临桂县| 吐鲁番市| 彭水| 固安县| 乌兰察布市| 西峡县| 婺源县| 塔城市| 德格县| 双峰县| 长岛县| 密山市| 子洲县| 昌邑市| 务川| 革吉县|