Skip to content

Commit

Permalink
update: 添加 module 示例源码
Browse files Browse the repository at this point in the history
  • Loading branch information
mqyqingfeng committed Nov 13, 2018
1 parent 5ed1bd7 commit b459941
Show file tree
Hide file tree
Showing 22 changed files with 2,390 additions and 0 deletions.
10 changes: 10 additions & 0 deletions demos/ES6/module/ES6/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>ES6</title>
</head>
<body>
<h1>Content</h1>
<script src="vender/main.js" type="module"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions demos/ES6/module/ES6/vender/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
console.log('加载了 add 模块')

var add = function(x, y) {
return x + y;
};

export {add}
5 changes: 5 additions & 0 deletions demos/ES6/module/ES6/vender/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {add} from './add.js';
console.log(add(1, 1))

import {square} from './square.js';
console.log(square(3))
7 changes: 7 additions & 0 deletions demos/ES6/module/ES6/vender/multiply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
console.log('加载了 multiply 模块')

var multiply = function(x, y) { 
return x * y;
};

export {multiply}
9 changes: 9 additions & 0 deletions demos/ES6/module/ES6/vender/square.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
console.log('加载了 square 模块')

import {multiply} from './multiply.js';

var square = function(num) { 
return multiply(num, num);
};

export {square}
7 changes: 7 additions & 0 deletions demos/ES6/module/commonJS/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
console.log('加载了 add 模块')

var add = function(x, y) { 
return x + y;
};

module.exports.add = add;
5 changes: 5 additions & 0 deletions demos/ES6/module/commonJS/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var add = require('./add.js');
console.log(add.add(1, 1))

var square = require('./square.js');
console.log(square.square(3))
7 changes: 7 additions & 0 deletions demos/ES6/module/commonJS/multiply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
console.log('加载了 multiply 模块')

var multiply = function(x, y) { 
return x * y;
};

module.exports.multiply = multiply;
10 changes: 10 additions & 0 deletions demos/ES6/module/commonJS/square.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
console.log('加载了 square 模块')

var multiply = require('./multiply.js');


var square = function(num) { 
return multiply.multiply(num, num);
};

module.exports.square = square;
10 changes: 10 additions & 0 deletions demos/ES6/module/requirejs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title>require.js</title>
</head>
<body>
<h1>Content</h1>
<script data-main="vender/main" src="vender/require.js"></script>
</body>
</html>
12 changes: 12 additions & 0 deletions demos/ES6/module/requirejs/vender/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
define(function() {

console.log('加载了 add 模块')

var add = function(x, y) { 
return x + y;
};

return {      
add: add
};
});
4 changes: 4 additions & 0 deletions demos/ES6/module/requirejs/vender/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
require(['./add', './square'], function(addModule, squareModule) {
console.log(addModule.add(1, 1))
console.log(squareModule.square(3))
});
12 changes: 12 additions & 0 deletions demos/ES6/module/requirejs/vender/multiply.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
define(function() {

console.log('加载了 multiply 模块')

var multiply = function(x, y) { 
return x * y;
};

return {      
multiply: multiply
};
});
Loading

0 comments on commit b459941

Please sign in to comment.