模块加载原理
程序员文章站
2022-05-18 20:16:16
var depMods = (function(){ var modules = {}; var defined = function(name,deps,impl){ typeof deps == 'function' && ( impl = deps, deps = [] ) if(deps.l ......
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()); });
上一篇: Python Web(三)
下一篇: CSS 学习手册