aboutsummaryrefslogtreecommitdiff
path: root/vim/bundle/vim-snippets/UltiSnips/javascript.snippets
blob: 4537baea6413724f55b014cddcec67589144b0ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
priority -50

###########################################################################
#                            TextMate Snippets                            #
###########################################################################
snippet get "Get Elements"
getElement${1/(T)|.*/(?1:s)/}By${1:T}${1/(T)|(I)|.*/(?1:agName)(?2:d)/}('$2')
endsnippet

snippet '':f "object method string"
'${1:${2:#thing}:${3:click}}': function(element) {
	${VISUAL}$0
}${10:,}
endsnippet

snippet :f "Object Method"
${1:method_name}: function(${3:attribute}) {
	${VISUAL}$0
}${10:,}
endsnippet

snippet :, "Object Value JS"
${1:value_name}: ${0:value},
endsnippet

snippet : "Object key key: 'value'"
${1:key}: ${2:"${3:value}"}${4:, }
endsnippet

snippet proto "Prototype (proto)"
${1:class_name}.prototype.${2:method_name} = function(${3:first_argument}) {
	${VISUAL}$0
};

endsnippet

snippet for "for (...) {...} (counting up)" b
for (var ${1:i} = 0, ${2:len} = ${3:Things.length}; $1 < $2; $1++) {
	${VISUAL}$0
}
endsnippet

snippet ford "for (...) {...} (counting down, faster)" b
for (var ${2:i} = ${1:Things.length} - 1; $2 >= 0; $2--) {
	${VISUAL}$0
}
endsnippet

snippet fun "function (fun)"
function ${1:function_name}(${2:argument}) {
	${VISUAL}$0
}
endsnippet

snippet vf "Function assigned to var"
${1:var }${2:function_name} = function $2(${3}) {
	${VISUAL}$0
};
endsnippet

snippet af "Anonymous Function" i
function($1) {
	${VISUAL}$0
}
endsnippet

snippet iife "Immediately-Invoked Function Expression (iife)"
(function(${1:window}) {
	${VISUAL}$0
}(${2:$1}));
endsnippet

snippet timeout "setTimeout function"
setTimeout(function() {
	${VISUAL}$0
}${2:.bind(${3:this})}, ${1:10});
endsnippet

snippet fi "for prop in obj using hasOwnProperty" b
for (${1:prop} in ${2:obj}){
	if ($2.hasOwnProperty($1)) {
		${VISUAL}$0
	}
}
endsnippet

# Snippets for Console Debug Output

snippet ca "console.assert" b
console.assert(${1:assertion}, ${2:"${3:message}"});
endsnippet

snippet cclear "console.clear" b
console.clear();
endsnippet

snippet cdir "console.dir" b
console.dir(${1:object});
endsnippet

snippet cdirx "console.dirxml" b
console.dirxml(${1:object});
endsnippet

snippet ce "console.error" b
console.error(${1:"${2:value}"});
endsnippet

snippet cgroup "console.group" b
console.group("${1:label}");
${VISUAL}$0
console.groupEnd();
endsnippet

snippet cgroupc "console.groupCollapsed" b
console.groupCollapsed("${1:label}");
${VISUAL}$0
console.groupEnd();
endsnippet

snippet ci "console.info" b
console.info(${1:"${2:value}"});
endsnippet

snippet cl "console.log" b
console.log(${1:"${2:value}"});
endsnippet

snippet cd "console.debug" b
console.debug(${1:"${2:value}"});
endsnippet

snippet cprof "console.profile" b
console.profile("${1:label}");
${VISUAL}$0
console.profileEnd();
endsnippet

snippet ctable "console.table" b
console.table(${1:"${2:value}"});
endsnippet

snippet ctime "console.time" b
console.time("${1:label}");
${VISUAL}$0
console.timeEnd("$1");
endsnippet

snippet ctimestamp "console.timeStamp" b
console.timeStamp("${1:label}");
endsnippet

snippet ctrace "console.trace" b
console.trace();
endsnippet

snippet cw "console.warn" b
console.warn(${1:"${2:value}"});
endsnippet

# AMD (Asynchronous Module Definition) snippets

snippet def "define an AMD module"
define(${1:optional_name, }[${2:'jquery'}], ${3:callback});
endsnippet

snippet req "require an AMD module"
require([${1:'dependencies'}], ${2:callback});
endsnippet

# vim:ft=snippets: