├── 3. AMD和CMD ├── 3-1. 浏览器端模块化的难题 │ ├── b.js │ ├── a.js │ ├── index.js │ ├── index.html │ ├── 笔记.md │ └── 笔记.html ├── 3-3. CMD │ ├── js │ │ ├── a.js │ │ ├── b.js │ │ ├── index.js │ │ └── sea.js │ ├── 笔记.md │ └── index.html └── 3-2. AMD │ ├── 笔记.md │ ├── js │ ├── a.js │ ├── index.js │ └── b.js │ └── index.html ├── 4. ES6模块化 ├── 4-2. 基本导入导出 │ ├── module │ │ ├── init.js │ │ ├── b.js │ │ ├── index.js │ │ └── a.js │ ├── assets │ │ └── 2019-12-03-17-00-44.png │ ├── index.html │ ├── 笔记.md │ └── 笔记.html ├── 4-5. ES6模块化练习 │ ├── module │ │ ├── index.js │ │ ├── game.js │ │ ├── map.js │ │ ├── ui.js │ │ └── play.js │ ├── imgs │ │ ├── box.png │ │ ├── player.png │ │ ├── wall.jpg │ │ └── over_box.png │ └── index.html ├── 4-4. ES6模块化的其他细节 │ ├── module │ │ ├── a.js │ │ ├── arrayPatcher.js │ │ ├── m1.js │ │ ├── m2.js │ │ ├── m.js │ │ └── index.js │ ├── assets │ │ └── 2019-12-04-14-33-14.png │ ├── index.html │ ├── 笔记.md │ └── 笔记.html ├── 4-3. 默认导入导出 │ ├── module │ │ ├── a.js │ │ └── index.js │ ├── assets │ │ └── 2019-12-03-17-00-44.png │ ├── index.html │ ├── 笔记.md │ └── 笔记.html └── 4-1. ES6模块化简介 │ └── 笔记.md ├── 2. CommonJS ├── 2-2. CommonJS │ ├── b.js │ ├── util.js │ ├── assets │ │ ├── 2019-12-02-11-15-01.png │ │ └── 2019-12-02-11-27-12.png │ ├── index.js │ ├── 笔记.md │ └── 笔记.html ├── 2-1. 安装nodejs │ ├── index.js │ ├── assets │ │ ├── 2019-12-02-10-57-23.png │ │ └── 2019-12-02-10-59-43.png │ └── 笔记.md └── 2-3. CommonJS练习 │ ├── test.js │ ├── 练习题.md │ ├── util.js │ ├── index.js │ └── poker.js └── 1. 概述 └── 1-1. JS模块化发展史 ├── assets └── 2019-11-28-15-45-47.png ├── 笔记.md └── 笔记.html /3. AMD和CMD/3-1. 浏览器端模块化的难题/b.js: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /3. AMD和CMD/3-1. 浏览器端模块化的难题/a.js: -------------------------------------------------------------------------------- 1 | require("./b.js") -------------------------------------------------------------------------------- /4. ES6模块化/4-2. 基本导入导出/module/init.js: -------------------------------------------------------------------------------- 1 | console.log("初始化代码") -------------------------------------------------------------------------------- /4. ES6模块化/4-5. ES6模块化练习/module/index.js: -------------------------------------------------------------------------------- 1 | import "./game.js" -------------------------------------------------------------------------------- /4. ES6模块化/4-2. 基本导入导出/module/b.js: -------------------------------------------------------------------------------- 1 | console.log("b模块运行了") 2 | 3 | export var b = 123; -------------------------------------------------------------------------------- /3. AMD和CMD/3-1. 浏览器端模块化的难题/index.js: -------------------------------------------------------------------------------- 1 | //一大堆代码 2 | require("./a.js") //同步代码,必须等待 3 | //一大堆代码 -------------------------------------------------------------------------------- /2. CommonJS/2-2. CommonJS/b.js: -------------------------------------------------------------------------------- 1 | console.log("b模块执行了!") 2 | 3 | var u = require("./util"); 4 | 5 | console.log(u.abc); -------------------------------------------------------------------------------- /4. ES6模块化/4-4. ES6模块化的其他细节/module/a.js: -------------------------------------------------------------------------------- 1 | export var name = "模块a"; 2 | 3 | export default function () { 4 | name = "module a"; 5 | } -------------------------------------------------------------------------------- /4. ES6模块化/4-5. ES6模块化练习/imgs/box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuYi-Edu/DuYi-Modularity/HEAD/4. ES6模块化/4-5. ES6模块化练习/imgs/box.png -------------------------------------------------------------------------------- /4. ES6模块化/4-4. ES6模块化的其他细节/module/arrayPatcher.js: -------------------------------------------------------------------------------- 1 | Array.prototype.print = function () { 2 | console.log(this); 3 | } 4 | 5 | //一些其他的代码 -------------------------------------------------------------------------------- /4. ES6模块化/4-5. ES6模块化练习/imgs/player.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuYi-Edu/DuYi-Modularity/HEAD/4. ES6模块化/4-5. ES6模块化练习/imgs/player.png -------------------------------------------------------------------------------- /4. ES6模块化/4-5. ES6模块化练习/imgs/wall.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuYi-Edu/DuYi-Modularity/HEAD/4. ES6模块化/4-5. ES6模块化练习/imgs/wall.jpg -------------------------------------------------------------------------------- /2. CommonJS/2-1. 安装nodejs/index.js: -------------------------------------------------------------------------------- 1 | console.log("Hello NodeJs");//是不是ES标准 2 | setInterval(function(){ 3 | console.log("Hello") 4 | }, 1000) -------------------------------------------------------------------------------- /4. ES6模块化/4-5. ES6模块化练习/imgs/over_box.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuYi-Edu/DuYi-Modularity/HEAD/4. ES6模块化/4-5. ES6模块化练习/imgs/over_box.png -------------------------------------------------------------------------------- /2. CommonJS/2-2. CommonJS/util.js: -------------------------------------------------------------------------------- 1 | var count = 0; //需要隐藏的内部实现 2 | 3 | console.log("util模块执行了!") 4 | 5 | module.exports = { 6 | abc: 123 7 | } -------------------------------------------------------------------------------- /4. ES6模块化/4-3. 默认导入导出/module/a.js: -------------------------------------------------------------------------------- 1 | export var a = 1; 2 | export var b = 2; 3 | 4 | export default { 5 | fn: function () { }, 6 | name: "adsfaf" 7 | } -------------------------------------------------------------------------------- /1. 概述/1-1. JS模块化发展史/assets/2019-11-28-15-45-47.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuYi-Edu/DuYi-Modularity/HEAD/1. 概述/1-1. JS模块化发展史/assets/2019-11-28-15-45-47.png -------------------------------------------------------------------------------- /4. ES6模块化/4-2. 基本导入导出/assets/2019-12-03-17-00-44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuYi-Edu/DuYi-Modularity/HEAD/4. ES6模块化/4-2. 基本导入导出/assets/2019-12-03-17-00-44.png -------------------------------------------------------------------------------- /4. ES6模块化/4-3. 默认导入导出/assets/2019-12-03-17-00-44.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuYi-Edu/DuYi-Modularity/HEAD/4. ES6模块化/4-3. 默认导入导出/assets/2019-12-03-17-00-44.png -------------------------------------------------------------------------------- /2. CommonJS/2-1. 安装nodejs/assets/2019-12-02-10-57-23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuYi-Edu/DuYi-Modularity/HEAD/2. CommonJS/2-1. 安装nodejs/assets/2019-12-02-10-57-23.png -------------------------------------------------------------------------------- /2. CommonJS/2-1. 安装nodejs/assets/2019-12-02-10-59-43.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuYi-Edu/DuYi-Modularity/HEAD/2. CommonJS/2-1. 安装nodejs/assets/2019-12-02-10-59-43.png -------------------------------------------------------------------------------- /2. CommonJS/2-2. CommonJS/assets/2019-12-02-11-15-01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuYi-Edu/DuYi-Modularity/HEAD/2. CommonJS/2-2. CommonJS/assets/2019-12-02-11-15-01.png -------------------------------------------------------------------------------- /2. CommonJS/2-2. CommonJS/assets/2019-12-02-11-27-12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuYi-Edu/DuYi-Modularity/HEAD/2. CommonJS/2-2. CommonJS/assets/2019-12-02-11-27-12.png -------------------------------------------------------------------------------- /3. AMD和CMD/3-3. CMD/js/a.js: -------------------------------------------------------------------------------- 1 | define(function (require, exports, module) { 2 | var b = require("b") 3 | console.log("a模块的内部代码", b) 4 | module.exports = "a模块的内容" 5 | }) -------------------------------------------------------------------------------- /4. ES6模块化/4-3. 默认导入导出/module/index.js: -------------------------------------------------------------------------------- 1 | // import data from "./a.js" //将a.js模块中的默认导出放置到常量data中 2 | import data, { a, b } from "./a.js" 3 | 4 | console.log(data, a, b) 5 | 6 | -------------------------------------------------------------------------------- /4. ES6模块化/4-4. ES6模块化的其他细节/assets/2019-12-04-14-33-14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DuYi-Edu/DuYi-Modularity/HEAD/4. ES6模块化/4-4. ES6模块化的其他细节/assets/2019-12-04-14-33-14.png -------------------------------------------------------------------------------- /3. AMD和CMD/3-3. CMD/js/b.js: -------------------------------------------------------------------------------- 1 | define(function (require, exports, module) { 2 | //模块内部的代码 3 | console.log("b模块的内部代码") 4 | module.exports = { 5 | name: "b模块", 6 | data: "b模块的数据" 7 | } 8 | }) -------------------------------------------------------------------------------- /3. AMD和CMD/3-3. CMD/js/index.js: -------------------------------------------------------------------------------- 1 | define((require, exports, module) => { 2 | require.async("a", function(a){ 3 | console.log(a) 4 | }) 5 | require.async("b", function(b){ 6 | console.log(b) 7 | }) 8 | }) -------------------------------------------------------------------------------- /4. ES6模块化/4-2. 基本导入导出/module/index.js: -------------------------------------------------------------------------------- 1 | import "./b.js"; 2 | import "./init.js" 3 | import * as a from "./a.js" 4 | 5 | // var b = 3; 6 | // console.log(b2) 7 | // console.log(name, age); 8 | // console.log(b) 9 | 10 | console.log(a.a, a.age, a.name) -------------------------------------------------------------------------------- /3. AMD和CMD/3-3. CMD/笔记.md: -------------------------------------------------------------------------------- 1 | # CMD 2 | 3 | 全称是Common Module Definition,公共模块定义规范 4 | 5 | sea.js实现了CMD规范 6 | 7 | 在CMD中,导入和导出模块的代码,都必须放置在define函数中 8 | 9 | ```js 10 | 11 | define(function(require, exports, module){ 12 | //模块内部的代码 13 | }) 14 | 15 | ``` -------------------------------------------------------------------------------- /4. ES6模块化/4-4. ES6模块化的其他细节/module/m1.js: -------------------------------------------------------------------------------- 1 | export const a = "m1-a"; 2 | export const b = "m1-b"; 3 | export const c = "m1-c"; 4 | 5 | export default "m1-default"; 6 | 7 | /* 8 | { 9 | a:xx, 10 | b:xx, 11 | c:xx, 12 | default:xxx 13 | } 14 | */ -------------------------------------------------------------------------------- /4. ES6模块化/4-4. ES6模块化的其他细节/module/m2.js: -------------------------------------------------------------------------------- 1 | export const a = "m2-a"; 2 | export const k = "m2-k"; 3 | export const t = "m2-t"; 4 | 5 | export default "m2-default"; 6 | 7 | /* 8 | { 9 | a:xx, 10 | k:xx, 11 | t:xx, 12 | default:xxx 13 | } 14 | */ -------------------------------------------------------------------------------- /2. CommonJS/2-2. CommonJS/index.js: -------------------------------------------------------------------------------- 1 | 2 | //nodejs中导入模块,使用相对路径,并且必须以./或../开头 3 | var util1 = require("./util.js") 4 | var util2 = require("./util.js") 5 | console.log(util1 === util2); 6 | require("./b") 7 | require("./b") 8 | require("./b") 9 | require("./b") 10 | -------------------------------------------------------------------------------- /4. ES6模块化/4-4. ES6模块化的其他细节/module/m.js: -------------------------------------------------------------------------------- 1 | // import { a, b } from "./m1.js"; 2 | // import m2, { k } from "./m2.js" 3 | 4 | // export { a, b, k, m2 as default } 5 | 6 | export { a, b } from "./m1.js" 7 | export { k, default, a as m2a } from "./m2.js" 8 | export const r = "m-r" -------------------------------------------------------------------------------- /3. AMD和CMD/3-2. AMD/笔记.md: -------------------------------------------------------------------------------- 1 | # AMD 2 | 3 | 全称是Asynchronous Module Definition,即异步模块加载机制 4 | 5 | require.js实现了AMD规范 6 | 7 | 在AMD中,导入和导出模块的代码,都必须放置在define函数中 8 | 9 | ```js 10 | 11 | define([依赖的模块列表], function(模块名称列表){ 12 | //模块内部的代码 13 | return 导出的内容 14 | }) 15 | 16 | ``` -------------------------------------------------------------------------------- /2. CommonJS/2-3. CommonJS练习/test.js: -------------------------------------------------------------------------------- 1 | // var util = require("./util") 2 | 3 | // var arr = [6,4,3,2,6,8,8,32,5]; 4 | 5 | // util.sortRandom(arr); 6 | 7 | // console.log(arr); 8 | 9 | var Poker = require("./poker") 10 | 11 | var p = new Poker(4, 11); 12 | console.log(p.toString()); -------------------------------------------------------------------------------- /3. AMD和CMD/3-2. AMD/js/a.js: -------------------------------------------------------------------------------- 1 | // define(["b"], function(b){ 2 | // console.log("a模块的内部代码") 3 | // return "a模块的内容"; 4 | // }) 5 | 6 | define(function (require, exports, module) { 7 | var b = require("b") 8 | console.log("a模块的内部代码", b) 9 | module.exports = "a模块的内容" 10 | }) -------------------------------------------------------------------------------- /3. AMD和CMD/3-2. AMD/js/index.js: -------------------------------------------------------------------------------- 1 | // define(["b", "a"], function (b, a) { 2 | // //等b.js加载完成后运行该函数 3 | // //模块内部的代码 4 | // console.log(b, a) 5 | // }) 6 | 7 | define((require, exports, module) => { 8 | var a = require("a"), 9 | b = require("b"); 10 | console.log(b, a) 11 | }) -------------------------------------------------------------------------------- /2. CommonJS/2-3. CommonJS练习/练习题.md: -------------------------------------------------------------------------------- 1 | 制作一个斗地主洗牌发牌的程序 2 | 3 | 划分模块: 4 | 5 | 1. 工具模块,导出一个函数,用于将一个数组中的所有内容乱序排列 6 | 2. 扑克牌构造函数(类) 7 | 1. 属性 8 | 1. 花色(1~4,♣、♥、♦、♠) 9 | 2. 牌面(1~15,14小王,15大王) 10 | 2. 方法 11 | 1. toString:得到该扑克牌的字符串 12 | 3. 入口模块(入口文件) 13 | 1. 创建54张扑克牌 14 | 2. 洗牌 15 | 3. 发牌 -------------------------------------------------------------------------------- /4. ES6模块化/4-4. ES6模块化的其他细节/module/index.js: -------------------------------------------------------------------------------- 1 | // // import method, { name } from "./a.js" 2 | 3 | // // console.log(name) 4 | // // method(); 5 | // // console.log(name) 6 | 7 | // import "./arrayPatcher.js" 8 | 9 | // var arr = [3,4,6,6,7]; 10 | // arr.print(); 11 | 12 | import * as m from "./m.js" 13 | 14 | console.log(m) -------------------------------------------------------------------------------- /4. ES6模块化/4-1. ES6模块化简介/笔记.md: -------------------------------------------------------------------------------- 1 | # ES6模块化简介 2 | 3 | ECMA组织参考了众多社区模块化标准,终于在2015年,随着ES6发布了官方的模块化标准,后成为ES6模块化 4 | 5 | ES6模块化具有以下的特点 6 | 7 | 1. 使用依赖**预声明**的方式导入模块 8 | 1. 依赖延迟声明 9 | 1. 优点:某些时候可以提高效率 10 | 2. 缺点:无法在一开始确定模块依赖关系(比较模糊) 11 | 2. 依赖预声明 12 | 1. 优点:在一开始可以确定模块依赖关系 13 | 2. 缺点:某些时候效率较低 14 | 2. 灵活的多种导入导出方式 15 | 3. 规范的路径表示法:所有路径必须以./或../开头 -------------------------------------------------------------------------------- /3. AMD和CMD/3-1. 浏览器端模块化的难题/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |