Skip to content

Commit 7f85298

Browse files
committed
update: js patterns descriptions
1 parent 9178fb4 commit 7f85298

File tree

8 files changed

+62
-14
lines changed

8 files changed

+62
-14
lines changed

snippets/js/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- [jQuery](jquery/)
66
- [Patterns](patterns/)
77
- [Design Patterns](patterns/design-patterns/)
8+
- [UMD](patterns/umd/)
89
- [Tests](tests/)
910
- [Common](common/)
1011
- [Chai](chai/)

snippets/js/patterns/design-patterns/README.md

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,22 @@
1111
### [jdp.constructor] Contructor
1212

1313
```javascript
14-
14+
var ${1:ConstructorName} = (function() {
15+
'use strict';
16+
function ${1:ConstructorName}(${2:args}) {
17+
// enforces new
18+
if (!(this instanceof ${1:ConstructorName})) {
19+
return new ${1:ConstructorName}(${2:args});
20+
}
21+
${3:// constructor body
22+
}
23+
}
24+
${4:${1:ConstructorName}.prototype.${5:methodName} = function(${6:args}) \{
25+
${7:// method body
26+
}
27+
\}};
28+
return ${1:ConstructorName};
29+
}());
1530
```
1631

1732
### [jdp.decorator] Decorator
@@ -53,7 +68,15 @@
5368
### [jdp.module] Module
5469

5570
```javascript
56-
71+
var ${1:moduleName} = (function() {
72+
'use strict';
73+
var ${1:moduleName} = {
74+
init: {
75+
$2
76+
}
77+
};
78+
return ${1:moduleName};
79+
}());
5780
```
5881

5982
### [jdp.observer] Observer
@@ -65,7 +88,15 @@
6588
### [jdp.prototype] Prototype
6689

6790
```javascript
68-
91+
function ${1:Car}() {
92+
// constructor...
93+
}
94+
${2:${1:Car}.prototype.${3:drive} = function () \{
95+
${4: // body...
96+
}
97+
\};}
98+
return ${1:Car};
99+
${0}
69100
```
70101

71102
### [jdp.rmodule] Revealing Module
@@ -77,5 +108,16 @@
77108
### [jdp.singleton] Singleton
78109

79110
```javascript
80-
111+
var ${1:name} = (function() {
112+
'use strict';
113+
var instance;
114+
${1:name} = function(${2:args}) {
115+
if (instance) {
116+
return instance;
117+
}
118+
instance = this;
119+
${3:// your code goes here
120+
}
121+
};
122+
return ${1:name};
81123
```

snippets/js/patterns/design-patterns/js-design-patterns-constructor.sublime-snippet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ var ${1:ConstructorName} = (function() {
99
}
1010
${3:// constructor body}
1111
}
12-
${4:${1:ConstructorName}.prototype.${5:methodName} = function(${6:args}) {
12+
${4:${1:ConstructorName}.prototype.${5:methodName} = function(${6:args}) \{
1313
${7:// method body}
1414
\}};
1515
return ${1:ConstructorName};

snippets/js/patterns/design-patterns/js-design-patterns-prototype.sublime-snippet

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<snippet>
22
<content><![CDATA[
33
function ${1:Car}() {
4-
// constructor...
4+
// constructor...
55
}
66
${2:${1:Car}.prototype.${3:drive} = function () \{
7-
${4: // body...}
7+
${4: // body...}
88
\};}
99
return ${1:Car};
1010
${0}

snippets/js/tests/README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Tests JavaScript Snippets
22

3-
- [Structure](structure/)
3+
- [Common](common/)
44
- afterEach
55
- after
66
- beforeEach
@@ -42,6 +42,8 @@
4242
- toMatch
4343
- toThrowError
4444
- toThrow
45+
- [Mocha](mocha/)
46+
-
4547
- [Node](node/)
4648
- assert
4749
- ok
@@ -57,4 +59,7 @@
5759
- notStrictEqual
5860
- strictEqual
5961
- throws
62+
- [QUnit](qunit/)
63+
-
6064
- [Sinon](sinon/)
65+
-

snippets/js/tests/mocha/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Mocha JavaScript Snippets
22

3-
## Prefix `tb.*`
3+
## Prefix `tm.*`
44

5-
### [tt.dequal] deepEqual
5+
### [tm.]
66

77
```javascript
88

snippets/js/tests/qunit/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# QUnit JavaScript Snippets
22

3-
## Prefix `tb.*`
3+
## Prefix `tq.*`
44

5-
### [tt.dequal] deepEqual
5+
### [tq.]
66

77
```javascript
88

snippets/js/tests/sinon/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Sinon JavaScript Snippets
22

3-
## Prefix `tb.*`
3+
## Prefix `ts.*`
44

5-
### [tt.dequal] deepEqual
5+
### [ts.]
66

77
```javascript
88

0 commit comments

Comments
 (0)