日期:2014-05-16  浏览次数:20381 次

使用 nodejs 形式的语法来规整 js
/*
 * 使用 nodejs 形式的语法来规整 js
 */ 
void function() {
	var mapping = {}, cache = {};
	window.define = function(id, func) {
		mapping[id] = func
	};
	window.require = function(id) {
		if (!/\.js$/.test(id)) {
			id += ".js"
		}
		if (cache[id]) {
			return cache[id]
		} else {
			return cache[id] = mapping[id]()
		}
	}
}();

define("scripts/core/demo.js", function(exports) {
	exports = {};
	
	exports.start = function() {
		alert("Hello World !")
	};
	
	return exports
});	

require('scripts/core/demo').start();
?