本文摘自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的模块加载器的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
jquery中deferred对象的用法介绍(附示例)
前端用nodejs能做什么
javascript预编译做了啥
javascript向php传递中文乱码怎么办
javascript单线程机制与settimeout执行原理的介绍(附代码)
web前端js是什么
javascript用什么方法触发按钮的被点击事件
jquery里面能不能写php方法?
javascript事件委托的详细介绍(附代码)
javascript如何改变原数组
更多相关阅读请进入《javascript》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » 使用javascript的模块加载器