doc: create "the module pattern" section

This commit is contained in:
Leon Xu committed 2021-08-31 19:34:14 -07:00
1 parent a40517e605
commit d42bfa4f6e
1 file changed
+10 -1
+10 -1
View File
@@ -60,4 +60,13 @@ for (let i = 0; i < divs.length; i++) {
当我们在JS文件的顶部写上"use strict"的时候,将打开严格的语法检查:
- 如果试图赋值给未声明的变量,则显示错误
- 阻止你重写关键JS系统库
- 禁止一些不安全或容易出错的语言特性
- 禁止一些不安全或容易出错的语言特性
## “模块模式”
```javascript
(function () {
// 语句
}) ();
```
- 将文件的所有代码包装在一个声明并立即调用的匿名函数中,详情[请看](http://adripofjavascript.com/blog/drips/an-introduction-to-iffes-immediately-invoked-function-expressions.html)
- 不会有全局符号被引入!