/*
* 使用 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();
[置顶] 使用 nodejs 形式的语法来规整 js
最新推荐文章于 2018-10-25 14:02:59 发布
本文介绍了一种使用NodeJS风格的脚本加载机制,并通过一个简单的示例演示了如何定义和加载模块。此机制允许开发者以更加模块化的方式组织代码。
548

被折叠的 条评论
为什么被折叠?



