谁能向我解释一下这个 javascript textmate 片段吗

发布于 2024-08-08 14:21:17 字数 184 浏览 2 评论 0原文

下面的代码是一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

年少掌心 2024-08-15 14:21:17

${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("")'.

岁月蹉跎了容颜 2024-08-15 14:21:17

我对 textmate 一无所知,但看起来它是生成以下内容:

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

但不是这样:

document.getElementsByName(val);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文