Skip to content

Commit 86816b8

Browse files
committed
Merge pull request scrooloose#15 from ekalinin/patch-1
Added new snippets for JavaScript
2 parents e8109db + d9aaba5 commit 86816b8

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

snippets/javascript.snippets

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,64 @@ snippet gett
9494
# console.log (Firebug)
9595
snippet cl
9696
console.log(${1});
97+
# return
98+
snippet ret
99+
return ${1:result}
100+
# for (property in object ) { ... }
101+
snippet fori
102+
for (var ${1:prop} in ${2:Things}) {
103+
${3:$2[$1]}
104+
};
105+
# hasOwnProperty
106+
snippet has
107+
hasOwnProperty(${1})
108+
# docstring
109+
snippet /**
110+
/**
111+
* ${1:description}
112+
*
113+
*/
114+
snippet @par
115+
@param {${1:type}} ${2:name} ${3:description}
116+
snippet @ret
117+
@return {${1:type}} ${2:description}
118+
119+
# JSON.parse
120+
snippet jsonp
121+
JSON.parse(${1:jstr});
122+
# JSON.stringify
123+
snippet jsons
124+
JSON.stringify(${1:object});
125+
# self-defining function
126+
snippet sdf
127+
var ${1:function_name} = function (${2:argument}) {
128+
${3:// initial code ...}
129+
130+
$1 = function ($2) {
131+
${4:// main code}
132+
};
133+
}
134+
# singleton
135+
snippet sing
136+
function ${1:Singleton} (${2:argument}) {
137+
// the cached instance
138+
var instance;
139+
140+
// rewrite the constructor
141+
$1 = function $1($2) {
142+
return instance;
143+
};
144+
145+
// carry over the prototype properties
146+
$1.prototype = this;
147+
148+
// the instance
149+
instance = new $1();
150+
151+
// reset the constructor pointer
152+
instance.constructor = $1;
153+
154+
${3:// code ...}
155+
156+
return instance;
157+
}

0 commit comments

Comments
 (0)