如果需要,请自行复制下或下载列代码清单到本地运行(如果不修改源码,这些文件需要在同一目录 ,并且以下列文件名对应)
我只在Chrome浏览器中调试过(现在也没去处理浏览器兼容方面的问题)
1. 代码
/**
* < main.js >
* @DATE 2012/11/29
* @author maolion.j@gmail.com
*
*/
//
Define( "module2", Depend( "module1", "@module1.m1" ), function( require, exports ){
console.log( "invoke @module2" );
exports.name = "@module2";
require("module1").say();
require("module2").print("maolion");
} );
Use( a = Module( "module1.js", "@module1.m1", "@module1.m2", "@module2" ), function( require ){
console.log( "invoke Main" );
var b = require( "module1" );
var x = require( "@module2" );
var c = require( "@module1.m1" );
var d = require( "@module1.m2" );
var x = require( "module2" );
x.print( "joye" );
//console.log(x.name);
} );
2.代码
/**
* < module1.js >
* @DATE 2012/11/29
* @author maolion.j@gmail.com
*
*/
Define( "module1" , Depend( "@module2", "module2" ), function( require, exports, module1 ){
console.log( "invoke module1" );
require("module2").print( "World" );
exports.say = function(){
console.log( "Hi! " + require( "@module2" ).name );
}
});
Define( "module1.m1", function( require, exports, m1 ){
console.log( "invoke module1.m1" );
});
Define( "module1.m2", function( require, exports, m2 ){
console.log( "invoke module1.m2" );
});
3. 代码
/**
* < module2.js >
* @DATE 2012/11/29
* @author maolion.j@gmail.com
* http://www.huiyi8.com/yinxiao/
*/音效网
Define( "module2", function( require, exports, module2 ){
console.log( "invoke module2" );
exports.print = function( str ){
console.log( "Hello, " + str );
}
});
4. 代码
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="content-type">
<title>Untitled</title>
<script type="text/javascript" src="Cox.Module.test.js"></script>
<script type="text/javascript" src="main.js"></script>
<script type="text/javascript">
confirm = function(){ return false };
</script>
</head>
<body>
<a href="/">index</a>
</body>
</html>