Skip to content

Commit

Permalink
添加详细的描述,重构代码
Browse files Browse the repository at this point in the history
  • Loading branch information
wchaowu committed Aug 15, 2013
1 parent 67d3997 commit 76093cf
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 23 deletions.
23 changes: 23 additions & 0 deletions AMD/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<h3>异步模块定义</h3><br />
AMD是"Asynchronous Module Definition"的缩写,意思就是"异步模块定义"。它采用异步方式加载模块,模块的加载不影响它后面语句的运行。<br />
所有依赖这个模块的语句,都定义在一个回调函数中,等到加载完成之后,这个回调函数才会运行。<br />
<br />
AMD也采用require()语句加载模块,但是不同于CommonJS,它要求两个参数:<br />
<code>

  require([module], callback);
</code>

第一个参数[module],是一个数组,里面的成员就是要加载的模块;第二个参数callback,则是加载成功之后的回调函数。如果将前面的代码改写成AMD形式,就是下面这样:<<br />
<code>

  require(['math'], function (math) {

    math.add(2, 3);

  });
<code>
<br />
math.add()与math模块加载不是同步的,浏览器不会发生假死。所以很显然,AMD比较适合浏览器环境。<br />

目前,主要有两个Javascript库实现了AMD规范:require.js和curl.js。本系列的第三部分,将通过介绍require.js,进一步讲解AMD的用法,以及如何将模块化编程投入实战。<br />
18 changes: 18 additions & 0 deletions CommonJS/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h3>CommonJS</h3>

2009年,美国程序员Ryan Dahl创造了node.js项目,将javascript语言用于服务器端编程。<br />

这标志"Javascript模块化编程"正式诞生。因为老实说,在浏览器环境下,没有模块也不是特别大的问题,毕竟网页程序的复杂性有限;<br />
但是在服务器端,一定要有模块,与操作系统和其他应用程序互动,否则根本没法编程。<br />
<br />
node.js的模块系统,就是参照CommonJS规范实现的。在CommonJS中,有一个全局性方法require(),用于加载模块。假定有一个数学模块math.js,就可以像下面这样加载。<br />
<code>
  var math = require('math');
<code>
然后,就可以调用模块提供的方法:<br />

<code>
  var math = require('math');
  math.add(2,3); // 5
<code>
因为这个系列主要针对浏览器编程,不涉及node.js,所以对CommonJS就不多做介绍了。我们在这里只要知道,require()用于加载模块就行了
99 changes: 76 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
--------------------------------------------------------------------------------
Version 1.0.0
javascript代码
Version 1.0.0 <br/>
Author:scott (吴超武) <br />
有什么疑问和建议请发邮箱至Email:wchaowu@gmail.com <br />
github:<a href="https://github.com/wchaowu/Javascript-Design-Patterns"> https://github.com/wchaowu/</a>
--------------------------------------------------------------------------------
Author:scott (吴超武) <br />
有什么疑问和建议请发邮箱至Email:wchaowu@gmail.com <br />
github:<a href="https://github.com/wchaowu/Javascript-Design-Patterns"> https://github.com/wchaowu/</a>
<br />
<br />

积累的一些javascript的写法
包含javascript的基础语法,面向对象的实现和设计模式实现

包含javascript的基础语法,面向对象的实现和设计模式实现,模块化开发 CommonJS AMD javascript常见的疑问,Jquery,Node.js html5
目录的Demo 建议大家按照顺序看
<h3>Oject-Oriented</h3>
1.<a href="https://github.com/wchaowu/javascript-code/tree/master/object-oriented/Expressive-JavaScript">JavaScript Expressive </a> <br />
Expand All @@ -22,27 +20,82 @@ github:<a href="https://github.com/wchaowu/Javascript-Design-Patterns"> https://
2.<a href="https://github.com/wchaowu/javascript-code/tree/master/javascript-based/this">JavaScript 闭包</a> <br />
3.<a href="https://github.com/wchaowu/javascript-code/tree/master/javascript-based/event">JavaScript 事件</a> <br />
<h3>Jquery</h3>
1 . jQuery中 closure
1 .<a href="https://github.com/wchaowu/javascript-code/blob/master/jquery/1_closure.js">
jQuery中 closure
</a>
<h3>Javascript-Design-Pattern</h3>
1 Singleton-Pattern <br />
2 Chaining <br />
3 Factory-Pattern <br />
4 Bridge-Pattern <br />
5 Composite-Pattern <br />
6 Facade-Pattern <br />
7 Adapter-Pattern <br />
8 Decorator-Pattern <br />
9 Flyweight-Pattern <br />
10 Proxy-Pattern <br />
11 Observer-Pattern <br />
12 Comman-Pattern <br />
13 Chain-of-Responsibility-Pattern <br />
1.
<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/The-Singleton-Pattern">
Singleton-Pattern
</a>
<br />
2.<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/Chaining">
Chaining
</a>
<br />
3<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/The-Factory-Pattern">
Factory-Pattern
</a>
<br />
4
<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/The-Bridge-Pattern">
Bridge-Pattern
</a>
<br />
5
<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/The-Bridge-Pattern">
Composite-Pattern
</a>
<br />
6
<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/The-Facade-Pattern">
Facade-Pattern
</a>
<br />
7
<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/The-Adapter-Pattern">
Adapter-Pattern
</a>

<br />
<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/The-Decorator-Pattern">
8 Decorator-Pattern
</a>
<br />
9
<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/The-Flyweight-Pattern">
Flyweight-Pattern
</a>
<br />
10
<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/The-Proxy-Pattern">
Proxy-Pattern
</a>
<br />
11
<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/The-Observer-Pattern">
Observer-Pattern
</a>
<br />
12
<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/The-Command-Pattern">
Command-Pattern
</a>
<br />
13
<a href="https://github.com/wchaowu/javascript-code/tree/master/JavaScript-Design-Patterns/The-Chain-of-Responsibility-Pattern">
Chain-of-Responsibility-Pattern
</a>

<br />

<h3>Javascript-疑问</h3>
1 function前加操作符

<h3> javascript 模块化规范</h3>
<h4>1. AMD</h4>
<h4>2. CommonJS></h4>
<h3>HTML5<h5>

------------------------
参考资料

Expand Down

0 comments on commit 76093cf

Please sign in to comment.