第2页 模块机制
- 章节名:模块机制
- 页码:第2页
5.5.1
var MyModules = (function Manager() { var modules = {}; function define(name, deps, impl) { for (var i = 0; i < deps.length; i++) { deps[i] = modules[deps[i]]; } modules[name] = impl.apply(impl, deps); } function get(name) { return modules[name]; } return { define: define, get: get }; })(); MyModules.define("bar", [], function() { function hello(who) { return "Let me introduce: " + who; } return { hello: hello }; }); MyModules.define("foo", ["bar"], function(bar) { var hungry = "hippo"; function awesome() { console.log(bar.hello(hungry).toUpperCase()); } return { awesome: awesome }; }); var bar = MyModules.get("bar"); var foo = MyModules.get("foo"); console.log(bar.hello("hippo")); // Let me introduce: hippo foo.awesome(); // LET ME INTRODUCE: HIPPO
11人阅读
○对本书的所有笔记 · · · · · ·
-
第1页 1
2.2.3 性能 引擎在代码中发现了eval(..)或with,它只能简单地假设关于标识符位置的判断都是无...
-
第2页 模块机制
-
第3页 第一部分 附录
动态作用域 function foo() { console.log(a); // 2 } function bar() { var a = 3; foo(); }...
-
第4页 this和对象
this既不指向函数自身也不指向函数的词法作用域 this的绑定和函数声明的位置没有任何关系,只...
> 查看全部5篇
说明 · · · · · ·
表示其中内容是对原文的摘抄