Skip to content

Commit 2167a0d

Browse files
committed
更新一点点
1 parent 532b53a commit 2167a0d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
- [函数声明](#函数声明)
6161
- [函数调用间隔](#函数调用间隔)
6262
- [立即调用的函数](#立即调用的函数)
63+
- [严格模式](#严格模式)
6364

6465
### 缩进层级
6566

@@ -1251,6 +1252,44 @@ function doSomething() {
12511252
}());
12521253
```
12531254
1255+
[返回顶部](#编程风格)
1256+
1257+
### 严格模式
1258+
- `use strict`
1259+
1260+
```javascript
1261+
// 不好的写法 - 全局严格模式
1262+
"use strict"
1263+
function doSomething() {
1264+
// 代码
1265+
}
1266+
1267+
// 好的写法
1268+
function doSomething() {
1269+
"use strict"
1270+
// 代码
1271+
}
1272+
```
1273+
1274+
- 如果希望在多个函数中应用严格模式而不必谢很多行的话,可以使用立即执行函数
1275+
1276+
```javascript
1277+
// 好的写法
1278+
(function() {
1279+
"use strict"
1280+
function doSomething() {
1281+
// 代码
1282+
}
1283+
function doSomethingElse() {
1284+
// 代码
1285+
}
1286+
})();
1287+
```
1288+
1289+
- 为什么不要全局使用严格模式?
1290+
+ 全局使用严格模式的情况下,其他文件中的(非严格模式下的)代码很可能会报错。
1291+
1292+
12541293
[返回顶部](#编程风格)
12551294
12561295
## 补足

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy