本文主要和大家分享javascript模块加载器详细说明,希望能帮助到大家。
定义
var mymodules = (function manager() {
var modules = {};
function define (name, deps, impl) {
for(var j = 0, length = deps.length; j < length; j++){
deps[j] = modules[deps[j]];
}
modules[name] = impl.apply(impl, deps);
}
function get (name) {
return modules[name];
}
return {
define: define,
get: get
}
})();
使用
mymodules.define('test1', [], function() {
function hello(name) {
console.log(name);
}
return {
hello: hello
}
});
mymodules.define('test2', ['test1'], function(test1) {
function age(name, age) {
console.log(test1.hello(name));
console.log(age);
}
return {
age: age
}
});
mymodules.get('test2').age('mumu', '27');
相关推荐:
requirejs实现一个简单的模块加载器实例分享
用js实现简易模块加载器的方法
概述如何实现一个简单的浏览器端js模块加载器
以上就是javascript模块加载器详细说明的详细内容。