使用javascript的模块加载器
这次给大家带来使用javascript的模块加载器,使用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');
相信看了本文案例你已经掌握了方法,更多精彩请关注云资源网其它相关文章!
推荐阅读:
Vue.directive()的图文详解
AjaxUpLoad.js怎样实现文件上传
以上就是使用javascript的模块加载器的详细内容,更多请关注云资源网其它相关文章!
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。


