From a59344e3b8a687e8ee3cbaf8576efcf21070efd3 Mon Sep 17 00:00:00 2001 From: Zhang Visper Date: Wed, 28 Oct 2015 16:52:29 +0800 Subject: [PATCH 1/2] add more variable naming suggestion --- javascript.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/javascript.md b/javascript.md index 61baf57..f68cc24 100644 --- a/javascript.md +++ b/javascript.md @@ -103,6 +103,29 @@ var foo_bar = 'hello eleme'; var fooBar = 'hello eleme'; ``` +尽可能做到见名知意: + +```js +// 不推荐 +var item; +var list; + +// 推荐 +var selectedNode; +var selectedNodeList; +``` + +数组的命名使用名词的复数形式或 List: + +```js +// 不推荐 +var fooBar = [foo, bar]; + +// 推荐 +var fooBars = [foo, bar]; +var fooBarList = [foo, bar]; +``` + ### 常量大写 ```js From bd944e87cf509ee17ce6172948539e2d13123e3f Mon Sep 17 00:00:00 2001 From: Zhang Visper Date: Wed, 28 Oct 2015 17:12:18 +0800 Subject: [PATCH 2/2] add a forbidden item --- javascript.md | 1 + 1 file changed, 1 insertion(+) diff --git a/javascript.md b/javascript.md index f68cc24..fd7365a 100644 --- a/javascript.md +++ b/javascript.md @@ -354,6 +354,7 @@ Promise.resolve() * 禁止使用 `eval`,非用不可时可以使用 `Function` 构造器替代。 * 禁止使用 `with` 语句。 +* 禁止使用 `for in` 循环遍历数组。 * 禁止在块作用域中使用函数声明语句。 ```js