Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
P
ProjectSpecification
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guohao
ProjectSpecification
Commits
9010f394
Commit
9010f394
authored
May 11, 2020
by
guohao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
docs(修改js代码规范): example code修改,var 替换为 let/const
parent
be08ed3a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
19 deletions
+19
-19
JS代码规范.md
docs/chapter1/JS代码规范.md
+19
-19
No files found.
docs/chapter1/JS代码规范.md
View file @
9010f394
...
...
@@ -10,17 +10,17 @@
-
构造函数,大写第一个字母
```
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
)
{
this
.
name
=
name
;
...
...
@@ -30,29 +30,29 @@ function Person(name) {
## 变量声明
一个函数作用域中所有的变量声明提到函数首部,除了for (...)里面使用的一次性变量。
var
的数量不做限制,但要统一,一行定义一个变量。
let
的数量不做限制,但要统一,一行定义一个变量。
```
js
// not good
function
doSomethingWithItems
(
items
)
{
var
a
,
let
a
,
b
;
var
value
=
10
;
var
result
=
value
+
10
;
let
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
;
}
}
// good
function
doSomethingWithItems
(
items
)
{
var
a
;
var
b
;
var
value
=
10
;
var
result
=
value
+
10
;
let
a
;
let
b
;
let
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
;
}
}
...
...
@@ -135,14 +135,14 @@ function test(a, b) {
}
}
var
a
;
let
a
;
if
(
a
===
null
)
{
...
}
// good
var
a
=
null
;
let
a
=
null
;
if
(
a
===
null
)
{
...
...
...
@@ -243,7 +243,7 @@ function test() {
new
Person
();
// good
var
person
=
new
Person
();
const
person
=
new
Person
();
// not good
delete
(
obj
.
attr
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment