Improvements to Javascript snippets by Vangelis Tsoumenis

This commit is contained in:
Holger Rapp 2013-03-21 11:54:20 +01:00
parent 7320873e04
commit 7b41b188f1
2 changed files with 63 additions and 16 deletions

View File

@ -6,19 +6,19 @@ getElement${1/(T)|.*/(?1:s)/}By${1:T}${1/(T)|(I)|.*/(?1:agName)(?2:d)/}('$2')
endsnippet endsnippet
snippet '':f "object method string" snippet '':f "object method string"
'${1:${2:#thing}:${3:click}}': function(element){ '${1:${2:#thing}:${3:click}}': function(element) {
$0 ${VISUAL}$0
}${10:,} }${10:,}
endsnippet endsnippet
snippet :f "Object Method" snippet :f "Object Method"
${1:method_name}: function(${3:attribute}){ ${1:method_name}: function(${3:attribute}) {
$0 ${VISUAL}$0
}${10:,} }${10:,}
endsnippet endsnippet
snippet :, "Object Value JS" snippet :, "Object Value JS"
${1:value_name}:${0:value}, ${1:value_name}: ${0:value},
endsnippet endsnippet
snippet : "Object key key: 'value'" snippet : "Object key key: 'value'"
@ -26,47 +26,93 @@ ${1:key}: ${2:"${3:value}"}${4:, }
endsnippet endsnippet
snippet proto "Prototype (proto)" snippet proto "Prototype (proto)"
${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) ,,{ ${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) {
${0:// body...} ${VISUAL}$0
}; };
endsnippet endsnippet
snippet for "for (...) {...} (faster)" snippet for "for (...) {...} (faster)"
for (var ${2:i} = ${1:Things}.length - 1; $2 >= 0; $2--){ for (var ${2:i} = ${1:Things}.length - 1; $2 >= 0; $2--) {
${3:$1[$2]}$0 ${3:$1[$2]}${VISUAL}$0
}; };
endsnippet endsnippet
snippet for "for (...) {...}" snippet for "for (...) {...}"
for (var ${2:i}=0; $2 < ${1:Things}.length; $2++) { for (var ${2:i}=0; $2 < ${1:Things}.length; $2++) {
${3:$1[$2]}$0 ${3:$1[$2]}${VISUAL}$0
}; };
endsnippet endsnippet
snippet fun "function (fun)" snippet fun "function (fun)"
function ${1:function_name} (${2:argument}) { function ${1:function_name} (${2:argument}) {
${0:// body...} ${VISUAL}$0
} }
endsnippet endsnippet
snippet iife "Immediately-Invoked Function Expression (iife)"
(function (${1:argument}) {
${VISUAL}$0
}(${2:$1}));
endsnippet
snippet ife "if ___ else" snippet ife "if ___ else"
if (${1:condition}) { if (${1:condition}) {
${2://code} ${2://code}
} }
else { else {
${3://code} ${3://code}
} }
endsnippet endsnippet
snippet if "if" snippet if "if"
if (${1:condition}) { if (${1:condition}) {
${0://code} ${VISUAL}$0
} }
endsnippet endsnippet
snippet timeout "setTimeout function" snippet timeout "setTimeout function"
setTimeout(function() {$0}${2:}, ${1:10}); setTimeout(function() {
${VISUAL}$0
}${2:.bind(${3:this})}, ${1:10});
endsnippet
# Snippets for Console Debug Output
snippet cl "console.log"
console.log(${1:"${2:value}"});
endsnippet
snippet cw "console.warn"
console.warn(${1:"${2:value}"});
endsnippet
snippet ce "console.error"
console.error(${1:"${2:value}"});
endsnippet
snippet ca "console.assert"
console.assert(${1:assertion}, ${2:"${3:message}"});
endsnippet
snippet cgroup "console.group"
console.group("${1:label}");
${VISUAL}$0
console.groupEnd();
endsnippet
snippet ctime "console.time"
console.time("${1:label}");
${VISUAL}$0
console.timeEnd("$1");
endsnippet
snippet ctimestamp "console.timestamp"
console.timeStamp("${1:label}")
endsnippet
snippet ctrace "console.trace"
console.trace();
endsnippet endsnippet
# vim:ft=snippets: # vim:ft=snippets:

View File

@ -1338,6 +1338,7 @@ Contributors listed in chronological order:
Paolo Cretaro (melko) Paolo Cretaro (melko)
Sergey Alexandrov (taketwo) Sergey Alexandrov (taketwo)
Jaromír Hradílek (jhradilek) Jaromír Hradílek (jhradilek)
Vangelis Tsoumenis (kioopi)
Thank you for your support. Thank you for your support.