File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 60
60
- [ 函数声明] ( #函数声明 )
61
61
- [ 函数调用间隔] ( #函数调用间隔 )
62
62
- [ 立即调用的函数] ( #立即调用的函数 )
63
+ - [ 严格模式] ( #严格模式 )
63
64
64
65
### 缩进层级
65
66
@@ -1251,6 +1252,44 @@ function doSomething() {
1251
1252
}());
1252
1253
` ` `
1253
1254
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
+
1254
1293
[返回顶部](#编程风格)
1255
1294
1256
1295
## 补足
You can’t perform that action at this time.
0 commit comments