Skip to content

Commit 1599268

Browse files
committed
06-01
1 parent 255dd21 commit 1599268

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
@@ -32,6 +32,9 @@
3232
#### 05
3333
* [05-01](https://github.com/TYRMars/JSlearn#05-01) `事件-知识点`
3434
* [05-02](https://github.com/TYRMars/JSlearn#05-02) `Ajax-XMLHttpRequest`
35+
* [05-03](https://github.com/TYRMars/JSlearn#05-03) `存储`
36+
#### 06
37+
* [06-01](https://github.com/TYRMars/JSlearn#06-01) `模块化`
3538

3639
---
3740

@@ -1389,6 +1392,42 @@ response.setHeader("Access-Control-Allow-Credentials","true");
13891392
* 是否会携带到ajax中
13901393
* API易用性
13911394

1395+
## 06-01
1396+
### 模块化
1397+
* 不使用模块化
1398+
* 使用模块化
1399+
* AMD
1400+
* CommonJS
1401+
#### 不使用模块化
1402+
* `util getFormatDate函数`
1403+
* `a-util.js aGetFormatDate函数 使用getFormatDate`
1404+
* `a.js aGetFormatDate`
1405+
* 定义
1406+
```JavaScript
1407+
//util.js
1408+
function getFormatDate(date,type) {
1409+
//type === 1返回 2017-06-15
1410+
//type === 2返回 2017年6月15日 格式
1411+
//...
1412+
}
1413+
//a-util.js
1414+
function aGetFormatDate(data) {
1415+
//返回
1416+
return getFormatDate(date,2);
1417+
}
1418+
// a.js
1419+
var dt = new Date()
1420+
console.log(aGetFormatDate(dt));
1421+
```
1422+
* 使用
1423+
1424+
```html
1425+
<script src="util.js"></script>
1426+
<script src="a-util.js"></script>
1427+
<script src="a.js"></script>
1428+
<!-- 1.这些代码中的函数必须是全局变量,才能暴露给使用方。全局变量污染 -->
1429+
<!-- 2. a.js 知道要引用 a-util.js ,但是他知道还需要依赖于util.js吗? -->
1430+
```
13921431

13931432
---
13941433

0 commit comments

Comments
 (0)