Skip to content

Commit d459c67

Browse files
committed
update: code with new patterns snippets
1 parent 3561dfd commit d459c67

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
<snippet>
22
<content><![CDATA[
3-
3+
var ${1:ConstructorName} = (function() {
4+
'use strict';
5+
function ${1:ConstructorName}(${2:args}) {
6+
// enforces new
7+
if (!(this instanceof ${1:ConstructorName})) {
8+
return new ${1:ConstructorName}(${2:args});
9+
}
10+
${3:// constructor body}
11+
}
12+
${4:${1:ConstructorName}.prototype.${5:methodName} = function(${6:args}) {
13+
${7:// method body}
14+
\}};
15+
return ${1:ConstructorName};
16+
}());
417
]]></content>
518
<tabTrigger>jdp.constructor</tabTrigger>
619
<description>jdp - Constructor</description>

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
<snippet>
22
<content><![CDATA[
3-
3+
var ${1:moduleName} = (function() {
4+
'use strict';
5+
var ${1:moduleName} = {
6+
init: {
7+
$2
8+
}
9+
};
10+
return ${1:moduleName};
11+
}());
412
]]></content>
513
<tabTrigger>jdp.module</tabTrigger>
614
<description>jdp - Module</description>

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<snippet>
22
<content><![CDATA[
3-
3+
function ${1:Car}() {
4+
// constructor...
5+
}
6+
${2:${1:Car}.prototype.${3:drive} = function () \{
7+
${4: // body...}
8+
\};}
9+
return ${1:Car};
10+
${0}
411
]]></content>
512
<tabTrigger>jdp.prototype</tabTrigger>
613
<description>jdp - Prototype</description>

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
<snippet>
22
<content><![CDATA[
3-
3+
var ${1:name} = (function() {
4+
'use strict';
5+
var instance;
6+
${1:name} = function(${2:args}) {
7+
if (instance) {
8+
return instance;
9+
}
10+
instance = this;
11+
${3:// your code goes here}
12+
};
13+
return ${1:name};
414
]]></content>
515
<tabTrigger>jdp.singleton</tabTrigger>
616
<description>jdp - Singleton</description>

0 commit comments

Comments
 (0)