Skip to content

Commit afa826d

Browse files
committed
添加描述
1 parent b3106b7 commit afa826d

File tree

39 files changed

+284
-138
lines changed

39 files changed

+284
-138
lines changed

JavaScript-Design-Patterns/Chaining/Building a chainable JavaScript library.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@ Function.prototype.method = function(name, fn) {
55
};
66
(function() {
77
function _$(els) {
8-
// ...
8+
// //todo
99
}
1010
/*
1111
Events
1212
* addEvent
1313
* getEvent
1414
*/
1515
_$.method('addEvent', function(type, fn) {
16-
// ...
16+
// //todo
1717
}).method('getEvent', function(e) {
18-
// ...
18+
// //todo
1919
}).
2020
/*
2121
DOM
@@ -27,7 +27,7 @@ Function.prototype.method = function(name, fn) {
2727
* setStyle
2828
*/
2929
method('addClass', function(className) {
30-
// ...
30+
// //todo
3131
}).method('removeClass', function(className) {
3232
// ...
3333
}).method('replaceClass', function(oldClass, newClass) {

JavaScript-Design-Patterns/Encapsulation-and-Information-Hiding/2-Fully exposed object.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var Book = function(isbn, title, author) {
66
}
77

88
Book.prototype.display = function() {
9-
...
9+
//todo...
1010
};
1111

1212

@@ -25,14 +25,15 @@ Book.prototype = {
2525
return false;
2626
}
2727

28-
isbn = isbn.replace(/-/. ''); // Remove dashes.
28+
isbn = isbn.replace(/-/, ''); // Remove dashes.
2929
if(isbn.length != 10 && isbn.length != 13) {
3030
return false;
3131
}
3232

3333
var sum = 0;
3434
if(isbn.length === 10) { // 10 digit ISBN.
35-
If(!isbn.match(\^\d{9}\)) { // Ensure characters 1 through 9 are digits.
35+
var re=/^\d{9}/
36+
if(!isbn.match(re)) { // Ensure characters 1 through 9 are digits.
3637
return false;
3738
}
3839

@@ -46,7 +47,8 @@ Book.prototype = {
4647
}
4748
}
4849
else { // 13 digit ISBN.
49-
if(!isbn.match(\^\d{12}\)) { // Ensure characters 1 through 12 are digits.
50+
var re =/^\d{12}\)/;
51+
if(!isbn.match(re)) { // Ensure characters 1 through 12 are digits.
5052
return false;
5153
}
5254

@@ -63,7 +65,7 @@ Book.prototype = {
6365
},
6466

6567
display: function() {
66-
...
68+
//todo
6769
}
6870
};
6971

@@ -84,7 +86,7 @@ var Book = function(isbn, title, author) { // implements Publication
8486

8587
Book.prototype = {
8688
checkIsbn: function(isbn) {
87-
...
89+
//todo
8890
},
8991
getIsbn: function() {
9092
return this.isbn;
@@ -109,6 +111,6 @@ Book.prototype = {
109111
},
110112

111113
display: function() {
112-
...
114+
//todo
113115
}
114116
};

JavaScript-Design-Patterns/Encapsulation-and-Information-Hiding/3 - Private methods with underscores.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var Book = function(isbn, title, author) { // implements Publication
66

77
Book.prototype = {
88
_checkIsbn: function(isbn) {
9-
...
9+
//todo
1010
},
1111
getIsbn: function() {
1212
return this._isbn;
@@ -31,6 +31,6 @@ Book.prototype = {
3131
},
3232

3333
display: function() {
34-
...
34+
//todo
3535
}
3636
};

JavaScript-Design-Patterns/Encapsulation-and-Information-Hiding/5 - Private methods with closures.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var Book = function(newIsbn, newTitle, newAuthor) { // implements Publication
55

66
// Private method.
77
function checkIsbn(isbn) {
8-
...
8+
//todo
99
}
1010

1111
// Privileged methods.
@@ -40,6 +40,6 @@ var Book = function(newIsbn, newTitle, newAuthor) { // implements Publication
4040
// Public, non-privileged methods.
4141
Book.prototype = {
4242
display: function() {
43-
...
43+
//todo
4444
}
4545
};

JavaScript-Design-Patterns/Encapsulation-and-Information-Hiding/6 - Static members.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var Book = (function() {
55

66
// Private static method.
77
function checkIsbn(isbn) {
8-
...
8+
//todo
99
}
1010

1111
// Return the constructor.
@@ -51,12 +51,12 @@ var Book = (function() {
5151

5252
// Public static method.
5353
Book.convertToTitleCase = function(inputString) {
54-
...
54+
//todo
5555
};
5656

5757
// Public, non-privileged methods.
5858
Book.prototype = {
5959
display: function() {
60-
...
60+
//todo
6161
}
6262
};

JavaScript-Design-Patterns/Encapsulation-and-Information-Hiding/7 - Constants.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ var Class = (function() {
44
var UPPER_BOUND = 100;
55

66
// Privileged static method.
7-
this.getUPPER_BOUND() {
7+
this.getUPPER_BOUND = function(){
88
return UPPER_BOUND;
99
}
1010

11-
...
11+
//todo
1212

1313
// Return the constructor.
1414
return function(constructorArgument) {
15-
...
15+
//todo
1616
}
1717
})();
1818

@@ -28,15 +28,15 @@ var Class = (function() {
2828
}
2929

3030
// Privileged static method.
31-
this.getConstant(name) {
31+
this.getConstant=function(name) {
3232
return constants[name];
3333
}
3434

35-
...
35+
//todo
3636

3737
// Return the constructor.
3838
return function(constructorArgument) {
39-
...
39+
//todo
4040
}
4141
})();
4242

JavaScript-Design-Patterns/The-Adapter-Pattern/1 - Characteristics of an adapter.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ var clientObject = {
44
string3: 'baz'
55
};
66
function interfaceMethod(str1, str2, str3) {
7-
...
7+
//todo
88
}
99

1010
function clientToInterfaceAdapter(o) {

JavaScript-Design-Patterns/The-Adapter-Pattern/4 - More on adapting an email API.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ dedMailtoFooMailAdapter.getMail = function(id, callback) {
2626
});
2727
};
2828
// Other methods needed to adapt dedMail to the fooMail interface.
29-
...
29+
//todo
3030

3131
// Assign the adapter to the fooMail variable.
3232
// 把适配器赋给fooMail变量,这样就不用修改客户端的其他代码了

JavaScript-Design-Patterns/The-Bridge-Pattern/6 - Where have bridges been used_.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ var addRequest = function(data) {
1414
// Bridge
1515

1616
var addRequestFromClick = function(request) {
17-
addRequest(request.split(-)[0]);
17+
addRequest(request.split('-')[0]);
1818
};

JavaScript-Design-Patterns/The-Chain-of-Responsibility-Pattern/1 - PublicLibrary class.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var Catalog = new Interface('Catalog', ['handleFilingRequest', 'findBooks',
1010
/* Book class. */
1111

1212
var Book = function(isbn, title, author, genres) { // implements Publication
13-
...
13+
//todo
1414
}
1515

1616

0 commit comments

Comments
 (0)