JS: Group related snippets together.

This commit is contained in:
Louis Pilfold 2014-10-09 10:47:38 +01:00
parent 6d36226a18
commit c34ee98d85

View File

@ -1,3 +1,5 @@
# Functions
# prototype # prototype
snippet proto snippet proto
${1:class_name}.prototype.${2:method_name} = function(${3}) { ${1:class_name}.prototype.${2:method_name} = function(${3}) {
@ -23,6 +25,18 @@ snippet (f
(function(${1}) { (function(${1}) {
${0} ${0}
}(${2})); }(${2}));
# self-defining function
snippet sdf
var ${1:function_name} = function (${2:argument}) {
${3}
$1 = function ($2) {
${0}
};
};
# Flow control
# if # if
snippet if snippet if
if (${1:true}) { if (${1:true}) {
@ -37,7 +51,7 @@ snippet ife
} }
# tertiary conditional # tertiary conditional
snippet ter snippet ter
${1:/* condition */} ? ${2:a} : ${0:b} ${1:/* condition */} ? ${2:/* if true */} : ${0:/* if false */}
# switch # switch
snippet switch snippet switch
switch (${1:expression}) { switch (${1:expression}) {
@ -54,21 +68,6 @@ snippet case
${2} ${2}
break; break;
${0} ${0}
# for (...) {...}
snippet for
for (var ${2:i} = 0, l = ${1:arr}.length; $2 < l; $2 ++) {
var ${3:v} = $1[$2];${0:}
}
# for (...) {...} (Improved Native For-Loop)
snippet forr
for (var ${2:i} = ${1:arr}.length - 1; $2 >= 0; $2 --) {
var ${3:v} = $1[$2];${0:}
}
# while (...) {...}
snippet wh
while (${1:/* condition */}) {
${0}
}
# try # try
snippet try snippet try
try { try {
@ -76,67 +75,48 @@ snippet try
} catch (${2:e}) { } catch (${2:e}) {
${0:/* handle error */} ${0:/* handle error */}
} }
# do...while # return
snippet ret
return ${0:result};
# Loops
# for loop
snippet for
for (var ${2:i} = 0, l = ${1:arr}.length; $2 < l; $2 ++) {
var ${3:v} = $1[$2];${0:}
}
# Reversed for loop
snippet forr
for (var ${2:i} = ${1:arr}.length - 1; $2 >= 0; $2 --) {
var ${3:v} = $1[$2];${0:}
}
# While loop
snippet wh
while (${1:/* condition */}) {
${0}
}
# Do while loop
snippet do snippet do
do { do {
${0} ${0}
} while (${1:/* condition */}); } while (${1:/* condition */});
# For in loop
snippet fori
for (var ${1:prop} in ${2:object}) {
${0:$2[$1]}
}
# Objects
# Object Method # Object Method
snippet :f snippet :f
${1:method_name}: function (${2:attribute}) { ${1:method_name}: function (${2:attribute}) {
${0} ${0}
}${3:,} }${3:,}
# setTimeout function
snippet timeout
setTimeout(function () {${0}}${2}, ${1:10});
# Get Elements
snippet get
getElementsBy${1:TagName}('${2}')
# Get Element
snippet gett
getElementBy${1:Id}('${2}')
# console.log (Firebug)
snippet cl
console.log(${0});
# console.debug (Firebug)
snippet cd
console.debug(${0});
# return
snippet ret
return ${0:result};
# for (property in object ) { ... }
snippet fori
for (var ${1:prop} in ${2:Things}) {
${0:$2[$1]}
}
# hasOwnProperty # hasOwnProperty
snippet has snippet has
hasOwnProperty(${0}) hasOwnProperty(${0})
# docstring
snippet /**
/**
* ${0:description}
*
*/
snippet @par
@param {${1:type}} ${2:name} ${0:description}
snippet @ret
@return {${1:type}} ${0:description}
# JSON.parse
snippet jsonp
JSON.parse(${0:jstr});
# JSON.stringify
snippet jsons
JSON.stringify(${0:object});
# self-defining function
snippet sdf
var ${1:function_name} = function (${2:argument}) {
${3}
$1 = function ($2) {
${0}
};
};
# singleton # singleton
snippet sing snippet sing
function ${1:Singleton} (${2:argument}) { function ${1:Singleton} (${2:argument}) {
@ -205,11 +185,61 @@ snippet prop
configurable : ${0:boolean} configurable : ${0:boolean}
} }
); );
# Documentation
# docstring
snippet /**
/**
* ${0:description}
*
*/
snippet @par
@param {${1:type}} ${2:name} ${0:description}
snippet @ret
@return {${1:type}} ${0:description}
# JSON
# JSON.parse
snippet jsonp
JSON.parse(${0:jstr});
# JSON.stringify
snippet jsons
JSON.stringify(${0:object});
# DOM selectors
# Get elements
snippet get
getElementsBy${1:TagName}('${2}')
# Get element
snippet gett
getElementBy${1:Id}('${2}')
# Elements by class
snippet by. snippet by.
${document}.getElementsByClassName('${class name}) ${document}.getElementsByClassName('${class name})
# Element by ID
snippet by# snippet by#
${document}.getElementById('${element ID}) ${document}.getElementById('${element ID})
# Query selector
snippet qs snippet qs
${document}.querySelector('${selectors}) ${document}.querySelector('${selectors})
# Query selector all
snippet qsa snippet qsa
${document}.querySelectorAll('${selectors}) ${document}.querySelectorAll('${selectors})
# Debugging
# console.log
snippet cl
console.log(${0});
# console.debug
snippet cd
console.debug(${0});
# Misc
# setTimeout function
snippet timeout
setTimeout(function () {${0}}${2}, ${1:10});