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

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.

主站蜘蛛池模板: 孝感市| 湖州市| 黑水县| 双柏县| 互助| 大化| 长宁县| 岚皋县| 习水县| 屯昌县| 阜南县| 故城县| 徐州市| 岳西县| 兴义市| 青阳县| 福州市| 中卫市| 罗定市| 晴隆县| 乌拉特后旗| 元朗区| 长垣县| 尉氏县| 夏邑县| 汝阳县| 阳山县| 通辽市| 黄梅县| 五峰| 龙山县| 会东县| 宣化县| 桦南县| 兴仁县| 麻栗坡县| 吉木萨尔县| 阿拉善左旗| 龙岩市| 武安市| 苏尼特左旗|