Skip to content

Commit 219b2a7

Browse files
committed
fixed intentation and encoding, updated reference list
1 parent 56837de commit 219b2a7

File tree

12 files changed

+358
-328
lines changed

12 files changed

+358
-328
lines changed

‎design-patterns/builder.html‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!doctype html>
1+
<!doctype html>
22
<htmllang="en">
33
<head>
44
<title>JavaScript Patterns</title>
@@ -7,6 +7,10 @@
77
<body>
88
<buttonid="test">Test</button>
99
<script>
10+
/* Title: Builder
11+
Description: constructs complex objects by separating construction and representation
12+
*/
13+
1014
functiongetBeerById(id,callback){
1115
// Make request for beer by ID, then return the beer data.
1216
asyncRequest('GET','beer.uri?id='+id,function(resp){
@@ -25,9 +29,7 @@
2529
}
2630

2731
// reference
28-
// http://www.jspatterns.com/
29-
// http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate
30-
// http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/
32+
// http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#builderpatternjquery
3133
</script>
3234
</body>
3335
</html>

‎design-patterns/chain-of-responsibility.html‎

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,61 @@
66
</head>
77
<body>
88
<script>
9-
// from https://gist.github.com/1174982
9+
/* Title: Chain of responsibility
10+
Description: delegates commands to a chain of processing objects
11+
*/
1012

1113
varNO_TOPIC=-1;
1214
varTopic;
1315

1416
functionHandler(s,t){
15-
this.successor=s||null;
16-
this.topic=t||0;
17+
this.successor=s||null;
18+
this.topic=t||0;
1719
}
1820

1921
Handler.prototype={
20-
handle: function(){
21-
console.log(this.has())
22-
if(this.successor){
23-
this.successor.handle()
24-
}
25-
console.log(this.topic);
26-
},
27-
has: function(){
28-
returnthis.topic!=NO_TOPIC;
22+
handle: function(){
23+
console.log(this.has());
24+
if(this.successor){
25+
this.successor.handle();
2926
}
27+
console.log(this.topic);
28+
},
29+
has: function(){
30+
returnthis.topic!=NO_TOPIC;
31+
}
3032
};
3133

3234
var_handle=Handler.prototype.handle;
3335

3436
varapp=newHandler({
35-
handle: function(){
36-
console.log('app handle');
37-
}
37+
handle: function(){
38+
console.log('app handle');
39+
}
3840
},3);
3941

4042
vardialog=newHandler(app,1);
4143
//dialog.handle = function (){
42-
//if (this.has()){
43-
//} else{
44-
//console.log('dialog handle');
45-
//_handle.call(this);
46-
//}
44+
//if (this.has()){
45+
//} else{
46+
//console.log('dialog handle');
47+
//_handle.call(this);
48+
//}
4749
//}
4850

4951
varbutton=newHandler(dialog,2);
5052
//button.handle = function (){
51-
//if (this.has()){
52-
//} else{
53-
//console.log('dialog handle');
54-
//_handle.call(this);
55-
//}
53+
//if (this.has()){
54+
//} else{
55+
//console.log('dialog handle');
56+
//_handle.call(this);
57+
//}
5658
//}
5759

5860
button.handle();
5961

6062
// reference
61-
// http://www.jspatterns.com/
62-
// http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate
63-
// http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/
63+
// https://gist.github.com/1174982
6464
</script>
6565
</body>
6666
</html>

‎design-patterns/command.html‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
<!doctype html>
1+
<!doctype html>
22
<htmllang="en">
33
<head>
44
<title>JavaScript Patterns</title>
55
<metacharset="utf-8">
66
</head>
77
<body>
88
<script>
9+
/* Title: Command
10+
Description: creates objects which encapsulate actions and parameters
11+
*/
12+
913
(function(){
1014

1115
varCarManager={
@@ -34,9 +38,7 @@
3438
})();
3539

3640
// reference
37-
// http://www.jspatterns.com/
38-
// http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate
39-
// http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/
41+
// http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#commandpatternjavascript
4042
</script>
4143
</body>
4244
</html>

‎design-patterns/decorator.html‎

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
1-
<!doctype html>
1+
<!doctype html>
22
<htmllang="en">
33
<head>
44
<title>JavaScript Patterns</title>
55
<metacharset="utf-8">
66
</head>
77
<body>
88
<script>
9-
vartree={};
10-
tree.decorate=function(){
11-
console.log('Make sure the tree won\'t fall');
12-
};
9+
/* Title: Decorator
10+
Description: dynamically adds/overrides behaviour in an existing method of an object
11+
*/
12+
13+
vartree={};
14+
tree.decorate=function(){
15+
console.log('Make sure the tree won\'t fall');
16+
};
1317

14-
tree.getDecorator=function(deco){
15-
tree[deco].prototype=this;
16-
returnnewtree[deco];
17-
};
18+
tree.getDecorator=function(deco){
19+
tree[deco].prototype=this;
20+
returnnewtree[deco];
21+
};
1822

19-
tree.RedBalls=function(){
20-
this.decorate=function(){
21-
this.RedBalls.prototype.decorate();
22-
console.log('Put on some red balls');
23-
}
24-
};
23+
tree.RedBalls=function(){
24+
this.decorate=function(){
25+
this.RedBalls.prototype.decorate();
26+
console.log('Put on some red balls');
27+
}
28+
};
2529

26-
tree.BlueBalls=function(){
27-
this.decorate=function(){
28-
this.BlueBalls.prototype.decorate();
29-
console.log('Add blue balls');
30-
}
31-
};
30+
tree.BlueBalls=function(){
31+
this.decorate=function(){
32+
this.BlueBalls.prototype.decorate();
33+
console.log('Add blue balls');
34+
}
35+
};
3236

33-
tree.Angel=function(){
34-
this.decorate=function(){
35-
this.Angel.prototype.decorate();
36-
console.log('An angel on the top');
37-
}
38-
};
37+
tree.Angel=function(){
38+
this.decorate=function(){
39+
this.Angel.prototype.decorate();
40+
console.log('An angel on the top');
41+
}
42+
};
3943

40-
tree=tree.getDecorator('BlueBalls');
41-
tree=tree.getDecorator('Angel');
42-
tree=tree.getDecorator('RedBalls');
44+
tree=tree.getDecorator('BlueBalls');
45+
tree=tree.getDecorator('Angel');
46+
tree=tree.getDecorator('RedBalls');
4347

44-
tree.decorate();
48+
tree.decorate();
4549

4650
// reference
47-
// http://www.jspatterns.com/
51+
// http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#decoratorpatternjavascript
4852
// http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate
49-
// http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/
5053
</script>
5154
</body>
5255
</html>

‎design-patterns/facade.html‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
</head>
77
<body>
88
<script>
9+
/* Title: Facade
10+
Description: provides a simplified interface to a large body of code
11+
*/
12+
913
varmobileEvent={
1014
// ...
1115
stop: function(e){
@@ -16,9 +20,8 @@
1620
};
1721

1822
// reference
19-
// http://www.jspatterns.com/
23+
// http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#facadepatternjavascript
2024
// http://shop.oreilly.com/product/9780596806767.do?sortby=publicationDate
21-
// http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/
2225
</script>
2326
</body>
2427
</html>

0 commit comments

Comments
(0)