Commit 9010f394 authored by guohao's avatar guohao

docs(修改js代码规范): example code修改,var 替换为 let/const

parent be08ed3a
...@@ -10,17 +10,17 @@ ...@@ -10,17 +10,17 @@
- 构造函数,大写第一个字母 - 构造函数,大写第一个字母
```js ```js
var thisIsMyName; let thisIsMyName;
var goodID; let goodID;
var reportURL; let reportURL;
var AndroidVersion; let AndroidVersion;
var iOSVersion; let iOSVersion;
var MAX_COUNT = 10; const MAX_COUNT = 10;
function Person(name) { function Person(name) {
this.name = name; this.name = name;
...@@ -30,29 +30,29 @@ function Person(name) { ...@@ -30,29 +30,29 @@ function Person(name) {
## 变量声明 ## 变量声明
一个函数作用域中所有的变量声明提到函数首部,除了for (...)里面使用的一次性变量。 一个函数作用域中所有的变量声明提到函数首部,除了for (...)里面使用的一次性变量。
var的数量不做限制,但要统一,一行定义一个变量。 let的数量不做限制,但要统一,一行定义一个变量。
```js ```js
// not good // not good
function doSomethingWithItems(items) { function doSomethingWithItems(items) {
var a, let a,
b; b;
var value = 10; let value = 10;
var result = value + 10; let result = value + 10;
for (var i = 0, len = items.length; i < len; i++) { for (let i = 0, len = items.length; i < len; i++) {
result += 10; result += 10;
} }
} }
// good // good
function doSomethingWithItems(items) { function doSomethingWithItems(items) {
var a; let a;
var b; let b;
var value = 10; let value = 10;
var result = value + 10; let result = value + 10;
for (var i = 0, len = items.length; i < len; i++) { for (let i = 0, len = items.length; i < len; i++) {
result += 10; result += 10;
} }
} }
...@@ -135,14 +135,14 @@ function test(a, b) { ...@@ -135,14 +135,14 @@ function test(a, b) {
} }
} }
var a; let a;
if (a === null) { if (a === null) {
... ...
} }
// good // good
var a = null; let a = null;
if (a === null) { if (a === null) {
... ...
...@@ -243,7 +243,7 @@ function test() { ...@@ -243,7 +243,7 @@ function test() {
new Person(); new Person();
// good // good
var person = new Person(); const person = new Person();
// not good // not good
delete(obj.attr); delete(obj.attr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment