Created
June 20, 2013 07:47
-
-
Save ufologist/5820937 to your computer and use it in GitHub Desktop.
SeaJS load module mechanism
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
seajs.use('./js/main', function(main) { | |
main.hello(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Hello SeaJS boilerplate</title> | |
<meta charset="utf-8" /> | |
</head> | |
<body> | |
<h1>SeaJS load module mechanism</h1> | |
<p>Open your console</p> | |
<ol> | |
<li>require module: main</li> | |
<li>require module: mod1</li> | |
<li>hello mod1</li> | |
<li>require module: mod2</li> | |
<li>hello mod2</li> | |
<li>hello main</li> | |
</ol> | |
<h2>Conclusion</h2> | |
<p>SeaJS execute modules as <strong>LAZY</strong> as possible(SeaJS只会在真正需要使用[依赖]模块时才执行该模块)</p> | |
<p>SeaJS async load modules, but execute them accordance with the order in your code(SeaJS是异步加载模块的没错, 但执行模块的顺序也是严格按照模块在代码中出现(require)的顺序, 这样才更符合逻辑吧! 你说呢, RequireJS?)</p> | |
<p>Test with SeaJS 2.0.0</p> | |
<script data-main="./js/app.js" src="lib/sea.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function(require, exports, module) { | |
console.log('require module: main'); | |
var mod1 = require('./mod1'); | |
mod1.hello(); | |
var mod2 = require('./mod2'); | |
mod2.hello(); | |
return { | |
hello: function() { | |
console.log('hello main'); | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function(require, exports, module) { | |
console.log('require module: mod1'); | |
return { | |
hello: function() { | |
console.log("hello mod1"); | |
} | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function(require, exports, module) { | |
console.log('require module: mod2'); | |
return { | |
hello: function() { | |
console.log("hello mod2"); | |
} | |
}; | |
}); |
执行结果
require module: main
require module: mod1
hello mod1
require module: mod2
hello mod2
hello main
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SeaJS execute modules as LAZY as possible(SeaJS只会在真正需要使用[依赖]模块时才执行该模块)
SeaJS async load modules, but execute them accordance with the order in your code(SeaJS是异步加载模块的没错, 但执行模块的顺序也是严格按照模块在代码中出现(require)的顺序, 这样才更符合逻辑吧! 你说呢, RequireJS?)
Test with SeaJS 2.0.0