使用 nodejs 形式的语法来规整 js
/** 使用 nodejs 形式的语法来规整 js
*/
void function() {
var mapping = {}, cache = {};
window.define = function(id, func) {
mapping = func
};
window.require = function(id) {
if (!/\.js$/.test(id)) {
id += ".js"
}
if (cache) {
return cache
} else {
return cache = mapping()
}
}
}();
define("scripts/core/demo.js", function(exports) {
exports = {};
exports.start = function() {
alert("Hello World !")
};
return exports
});
require('scripts/core/demo').start();
页:
[1]