JS: Group related snippets together.
This commit is contained in:
parent
6d36226a18
commit
c34ee98d85
@ -1,3 +1,5 @@
|
||||
# Functions
|
||||
|
||||
# prototype
|
||||
snippet proto
|
||||
${1:class_name}.prototype.${2:method_name} = function(${3}) {
|
||||
@ -23,6 +25,18 @@ snippet (f
|
||||
(function(${1}) {
|
||||
${0}
|
||||
}(${2}));
|
||||
# self-defining function
|
||||
snippet sdf
|
||||
var ${1:function_name} = function (${2:argument}) {
|
||||
${3}
|
||||
|
||||
$1 = function ($2) {
|
||||
${0}
|
||||
};
|
||||
};
|
||||
|
||||
# Flow control
|
||||
|
||||
# if
|
||||
snippet if
|
||||
if (${1:true}) {
|
||||
@ -37,7 +51,7 @@ snippet ife
|
||||
}
|
||||
# tertiary conditional
|
||||
snippet ter
|
||||
${1:/* condition */} ? ${2:a} : ${0:b}
|
||||
${1:/* condition */} ? ${2:/* if true */} : ${0:/* if false */}
|
||||
# switch
|
||||
snippet switch
|
||||
switch (${1:expression}) {
|
||||
@ -54,21 +68,6 @@ snippet case
|
||||
${2}
|
||||
break;
|
||||
${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
|
||||
snippet try
|
||||
try {
|
||||
@ -76,67 +75,48 @@ snippet try
|
||||
} catch (${2:e}) {
|
||||
${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
|
||||
do {
|
||||
${0}
|
||||
} while (${1:/* condition */});
|
||||
# For in loop
|
||||
snippet fori
|
||||
for (var ${1:prop} in ${2:object}) {
|
||||
${0:$2[$1]}
|
||||
}
|
||||
|
||||
# Objects
|
||||
|
||||
# Object Method
|
||||
snippet :f
|
||||
${1:method_name}: function (${2:attribute}) {
|
||||
${0}
|
||||
}${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
|
||||
snippet has
|
||||
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
|
||||
snippet sing
|
||||
function ${1:Singleton} (${2:argument}) {
|
||||
@ -205,11 +185,61 @@ snippet prop
|
||||
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.
|
||||
${document}.getElementsByClassName('${class name})
|
||||
# Element by ID
|
||||
snippet by#
|
||||
${document}.getElementById('${element ID})
|
||||
# Query selector
|
||||
snippet qs
|
||||
${document}.querySelector('${selectors})
|
||||
# Query selector all
|
||||
snippet qsa
|
||||
${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});
|
||||
|
Loading…
Reference in New Issue
Block a user