javascript.snippets 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. # Prototype
  2. snippet proto
  3. ${1:class_name}.prototype.${2:method_name} =
  4. function(${3:first_argument}) {
  5. ${4:// body...}
  6. };
  7. # Function
  8. snippet fun
  9. function ${1:function_name} (${2:argument}) {
  10. ${3:// body...}
  11. }
  12. # Anonymous Function
  13. snippet f
  14. function(${1}) {${2}};
  15. # if
  16. snippet if
  17. if (${1:true}) {${2}}
  18. # if ... else
  19. snippet ife
  20. if (${1:true}) {${2}}
  21. else{${3}}
  22. # tertiary conditional
  23. snippet t
  24. ${1:/* condition */} ? ${2:a} : ${3:b}
  25. # switch
  26. snippet switch
  27. switch(${1:expression}) {
  28. case '${3:case}':
  29. ${4:// code}
  30. break;
  31. ${5}
  32. default:
  33. ${2:// code}
  34. }
  35. # case
  36. snippet case
  37. case '${1:case}':
  38. ${2:// code}
  39. break;
  40. ${3}
  41. # for (...) {...}
  42. snippet for
  43. for (var ${2:i} = 0; $2 < ${1:Things}.length; $2${3:++}) {
  44. ${4:$1[$2]}
  45. };
  46. # for (...) {...} (Improved Native For-Loop)
  47. snippet forr
  48. for (var ${2:i} = ${1:Things}.length - 1; $2 >= 0; $2${3:--}) {
  49. ${4:$1[$2]}
  50. };
  51. # while (...) {...}
  52. snippet wh
  53. while (${1:/* condition */}) {
  54. ${2:/* code */}
  55. }
  56. # do...while
  57. snippet do
  58. do {
  59. ${2:/* code */}
  60. } while (${1:/* condition */});
  61. # Object Method
  62. snippet :f
  63. ${1:method_name}: function(${2:attribute}) {
  64. ${4}
  65. }${3:,}
  66. # setTimeout function
  67. snippet timeout
  68. setTimeout(function() {${3}}${2}, ${1:10};
  69. # Get Elements
  70. snippet get
  71. getElementsBy${1:TagName}('${2}')${3}
  72. # Get Element
  73. snippet gett
  74. getElementBy${1:Id}('${2}')${3}