谁能向我解释一下这个 javascript textmate 片段吗
下面的代码是一个textmate javascript片段,有人可以解释一下吗?因为我想在我自己的片段中使用这个功能。非常感谢。
document.getElement${1/(T)|.*/(?1:s)/}By${1:T}${1/(T)|(I)|.*/(?1:agName)(?2:d)/}("$2")
the following code is a textmate 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")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
${1:T}
是第一个制表符占位符,默认值为“T”。这是当您键入“get”并按 Tab 键时突出显示的文本。$2
是第二个选项卡占位符。按“T”或“I”完成第一个选项卡占位符中的函数名称后,您可以按选项卡到达此处。这些部分您可能已经知道,但其他两个部分稍微棘手一些。
${1/(T)|.*/(?1:s)/}
是一种插入开关。它会查看您在第一个选项卡占位符中键入的值,并选择要插入的相应值。如果您输入“T”,它将插入一个“s”(组成单词“Elements”);否则,它不会插入任何内容。${1/(T)|(I)|.*/(?1:agName)(?2:d)/}
是另一个插入开关,它再次查看您输入的值第一个制表符占位符(这就是开头的“1”的含义)。这里,有两种可能的插入:如果您输入“T”,它将补全为“Tagname”,如果您输入“I”,它将补全为“Id”。总体结果是,如果您调用代码片段并输入“T”,它将完成“getElementsByTagName("")”。如果您调用它并输入“I”,它将完成“getElementById("")”。
${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("")'.
我对 textmate 一无所知,但看起来它是生成以下内容:
但不是这样:
I know nothing about textmate, but looks like it is to generate the followings:
Not this though: