总是使用var声明变量,不然将其变为全局变量。我们要想办法避免全局空间污染。
//bad
aaa = new AAA();
//good
var aaa = new AAA();
//God bless!
使用var声明每个变量,这样很容易添加新的变量声明,而不用去担心a,替换a
//bad
var items = getItems();
goSportsTeam = true ;
dragonball = 'z';
//good
var items = getItems();
var goSportsTeam = true;
var dragonball = 'z';
//God bless!
在作用域定点对变量赋值,这有助于避免变量声明问题与声明提升相关问题。
1:7 And God made the firmament,and divided the waters which where under the firament from the waters which were above the firmament :and it was so.