【学习笔记】JavaScript编码规范-变量
2015-05-15 15:33
591 查看
总是使用var声明变量,不然将其变为全局变量。我们要想办法避免全局空间污染。
使用var声明每个变量,这样很容易添加新的变量声明,而不用去担心a,替换a
在作用域定点对变量赋值,这有助于避免变量声明问题与声明提升相关问题。
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.
//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.
相关文章推荐
- 【学习笔记】JavaScript编码规范-字符串
- 【学习笔记】JavaScript编码规范-声明提升
- 【学习笔记】JavaScript编码规范-比较运算符&相等
- 【学习笔记】JavaScript编码规范- 注释
- 【学习笔记】JavaScript编码规范-语句块
- 【学习笔记】JavaScript编码规范- 空白
- 【学习笔记】JavaScript编码规范-属性
- 【学习笔记】JavaScript编码规范-函数
- 【学习笔记】JavaScript编码规范-类型
- 【学习笔记】JavaScript编码规范-对象
- 【学习笔记】JavaScript编码规范-数组
- JavaScript基础学习笔记(二)--- 变量、作用域和内存问题
- JavaScript面向对象入门学习笔记——变量的作用域
- JavaScript学习笔记一:数据类型和变量
- Javascript学习笔记04 ——变量,作用域,内存问题
- JavaScript学习笔记(4)——JavaScript语法之变量
- javascript学习笔记_浅谈基础语法,类型,变量
- Kotlin 学习笔记(二) 编码规范和导入包
- Javascript学习笔记一基本数据类型与变量声明
- JavaScript学习笔记——变量