File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change 10
10
/*
11
11
* @Author : victorsun
12
12
* @Date : 2017-08-24 14:34:31
13
- * @Last Modified by: victorsun
14
- * @Last Modified time: 2017-08-24 14:48:26
13
+ * @Last Modified by: csxiaoyao
14
+ * @Last Modified time: 2018-04-15 14:25:56
15
15
*/
16
16
17
17
/**
27
27
* 浏览器,等待时间取决于网速的快慢,可能要等很长时间,浏览器处于"假死"状态
28
28
* 因此,浏览器端的模块,不能采用"同步加载"(synchronous),只能采用"异步加载"(asynchronous)
29
29
*/
30
- // 假定加载一个数学模块math.js
30
+ // 在模块中对外输出变量(任意对象、函数、数组等) module.exports = variable; module.exports = function(){}; module.exports = { hello: fun1, greet: fun2 };
31
+ // 引入其他模块输出的对象 var foo = require('other_module');
32
+ // 变量隔离使用闭包 (function () { var a = XXX; })();
33
+
34
+ // 例1:假定加载一个数学模块math.js
31
35
var math = require ( 'math' ) ;
32
36
math . add ( 2 , 3 ) ; // 5
33
37
38
+ // 例2:
39
+ // 模块定义文件 hello.js
40
+ function greet ( name ) {
41
+ console . log ( 'hello,' + name + '~' ) ;
42
+ }
43
+ module . exports = greet ;
44
+ // 引用模块 main.js
45
+ var greet = require ( './hello' ) ;
46
+ greet ( 'csxiaoyao' ) ; // hello,csxiaoyao~
47
+
34
48
/**
35
49
* 【 AMD 】
36
50
* AMD "Asynchronous Module Definition" 异步模块定义
You can’t perform that action at this time.
0 commit comments