开发者

can anyone explain this javascript textmate snippet to me please

the following code is a textmat开发者_如何学运维e javascript snippet, can anyone explain it please? cuz i want to use this feature in my own snippets. greate thanks.

document.getElement${1/(T)|.*/(?1:s)/}By${1:T}${1/(T)|(I)|.*/(?1:agName)(?2:d)/}("$2")


${1:T} is the first tab placeholder, with a default value of "T". This is the text that's highlighted when you type "get" and hit tab.

$2 is the second tab placeholder. Once you've pressed either "T" or "I" to complete the function name in the first tab placeholder, you can press tab to get here.

Those parts you probably knew already, but the other two are slightly trickier.

${1/(T)|.*/(?1:s)/} is a kind of insertion switch. It looks at the value you type into the first tab placeholder and picks a corresponding value to insert. If you type "T", it will insert an "s" (to make the word "Elements"); otherwise, it doesn't insert anything.

${1/(T)|(I)|.*/(?1:agName)(?2:d)/} is another insertion switch, which again looks at the value you type into the first tab placeholder (that's what the "1" at the beginning means). Here, there are two possible insertions: if you type "T", it will complete it to "Tagname", and if you type "I", it will complete it to "Id".

The overall result is that if you invoke the snippet and type "T", it will complete to 'getElementsByTagName("")'. If you invoke it and type "I", it will complete it to 'getElementById("")'.


I know nothing about textmate, but looks like it is to generate the followings:

document.getElementById(val);
document.getElementsByTagName(val);

Not this though:

document.getElementsByName(val);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜