使用javascript的模块加载器
导读:收集整理的这篇文章主要介绍了使用javascript的模块加载器,觉得挺不错的,现在分享给大家,也给大家做个参考。这次给大家带来使用javascript的模块加载器,使用javascript模块加载器的注意事项有哪些,下面就是实战案例,一起...
收集整理的这篇文章主要介绍了使用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的模块加载器的详细内容,更多请关注其它相关文章!
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: 使用javascript的模块加载器
本文地址: https://pptw.com/jishu/584006.html
