这次给大家带来使用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');
登录后复制
相信看了本文案例你已经掌握了方法,更多精彩请关注【创想鸟】其它相关文章!
推荐阅读:
使用javascript
使用javascript
以上就是使用javascript的模块加载器的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/3124659.html