您的位置:首页 > Web前端 > JavaScript

【学习笔记】JavaScript编码规范-变量

2015-05-15 15:33 591 查看
总是使用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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: