本文摘自PHP中文网,作者php中世界最好的语言,侵删。
这次给大家带来使用javascript的模块加载器,使用javascript模块加载器的注意事项有哪些,下面就是实战案例,一起来看一下。定义
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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
}
})();
|
使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | 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' );
|
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
Vue.directive()的图文详解
AjaxUpLoad.js怎样实现文件上传
以上就是使用javascript的模块加载器的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
javascript有几个对话框
了解js中的执行上下文、 执行栈、事件循环
javascript怎么求长度
js 如何获取 input 的 value 值?
jquery+jsonp跨域需要怎样实现
js实现图片无缝滚动
javascript字符串如何替换元素
10个使用console进行javascript调试的高级技巧
javascript弱类型什么意思
js中object.defineproperty的用法介绍(代码示例)
更多相关阅读请进入《javascript》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » 使用javascript的模块加载器