复制代码
var depMods = (function(){
var modules = {};
var defined = function(name,deps,impl){
typeof deps == 'function' && (
impl = deps,
deps = []
)
if(deps.length > 0){
for(let i = 0; i < deps.length; i++){
deps[i] = modules[deps[i]]
}
}
!modules[name] && (modules[name] = impl.apply(impl,deps))
}
var require = function(deps,handle){
if(!Array.isArray(deps)){
deps = [deps];
}
for(let i = 0; i < deps.length; i++){
deps[i] = modules[deps[i]]
}
handle.apply(handle,deps);
}
return {
defined:defined,
require:require
}
})();
depMods.defined('table',function(){
var initTable = function(){
return "初始化表格模块";
}
return {
initTable:initTable
}
});
depMods.require('table',function(table){
alert(table.initTable());
});
复制代码
|
|