javascript符号_JavaScript中的美元符号($)和下划线(_)javascript 符号
The dollar sign ($) and the underscore (_) characters are identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.
美元符号( $ ) 下划线( _ )字符是 标识符 ,这仅表⽰它们以与名称相同的⽅式标识对象。 他们标识的对象包括诸如变量,函数,属性,事件和对象之类的东西。
For this reason, the characters are not treated the same way as other special symbols. Instead, JavaScript
treats $ and _ as if they were letters of the alphabet.明确目标
因此,这些字符与其他特殊符号的处理⽅式不同。 相反,JavaScript将$和_当作字母来对待。
鳄鱼英语怎么读A JavaScript identifier — again, just a name for any object — must start with a lower or upper ca letter, underscore (_), or dollar sign ($); subquent characters can also include digits (0-9). Anywhere that an alphabetic character is allowed in JavaScript, 54 possible letters are available: any lowerca letter (a through z), any upperca letter (A through Z), $ and _.
同样,JavaScript标识符(仅是任何对象的名称)必须以⼩写或⼤写字母,下划线( _ )或美元符号( $ )开头; 后续字符也可以包括数字(0-9)。 在JavaScript中允许使⽤字母字符的任何地⽅,都可以使⽤54个可能的字母:任何⼩写字母(a到z),任何⼤写字母(A到Z), $和_ 。
爱的词语美元($)标识符 ( The Dollar ($) Identifier )
The dollar sign is commonly ud as a shortcut to the ElementById(). Becau this function is fairly verbo and ud frequently in , the $ has long been ud as its alias, and many of the libraries available for u with JavaScript create a $() function that references an element from the DOM if you pass it the id of that element.霍去病墓
美元符号通常⽤作函数ElementById()的快捷⽅式。 由于此函数相当冗长且经常在中 ,因此$长期以来⼀直⽤作其别名,并且许多可⽤于JavaScript的库都创建了⼀个$()函数,如果您将其传递给DOM,则该函数会引⽤DOM中的元素。该元素的ID。
There is nothing about $ that requires it to be ud this way, however. But it has been the convention, although there is nothing in the language to enforce it.
节约家庭>嬴稷和嬴政什么关系但是,没有任何关于$的要求。 但这是约定俗成的,尽管没有什么语⾔可以强制执⾏。
The dollar sign $ was chon for the function name by the first of the libraries becau it is a short one-character word, and $ was least likely to be ud by itlf as a function name and therefore the least likely to clash with other code in the page.
在这些库中的第⼀个中,函数名选择了美元符号$ ,因为它是⼀个短的单字符单词,并且$本⾝最不可能⽤作函数名,因此与其他代码冲突的可能性最⼩。在页⾯中。
Now multiple libraries are providing their own version of the $() function, so many now provide the option to turn off that definition in order to avoid clashes.
现在,多个库都提供了⾃⼰的$()函数版本,因此许多库现在提供了关闭该定义的选项,以避免发⽣冲突。
Of cour, you don't need to u a library to be able to u $(). All you need to substitute $() ElementById() is to add a definition of the $() function to your code as follows:
当然,您⽆需使⽤库即可使⽤$() 。 将$()替换为ElementById ()所需要做的就是向代码中添加$()函数的定义,如下所⽰:function $(x) {ElementById(x);}
下划线_标识符 ( The Underscore _ Identifier )
A convention has also developed regarding the u of _, which is frequently ud to preface the name of an object's property or method that is private. This is a quick and easy way to immediately identify a private class member, and it is so widely ud, that almost every programmer will recognize it.
芸汐传电视剧关于_的使⽤,也已经开发了⼀个约定,该约定通常⽤于在对象的私有属性或⽅法的名称前添加前缀。 这是⼀种⽴即识别私有类成员的快速简便的⽅法,它的⽤途⾮常⼴泛,⼏乎每个程序员都可以识别它。
This is particularly uful in JavaScript since defining fields as private or public is done without the u of the private and public keywords (at least this is true in the versions of JavaScript ud in web browrs — JavaScript 2.0 does allow the keywords).
一英文
这在JavaScript中特别有⽤,因为⽆需使⽤private和public关键字就可以将字段定义为private或public(⾄少在Web浏览器中使⽤JavaScript版本中是这样-JavaScript 2.0允许使⽤这些关键字)。
Note that again, as with $, the u of _ is merely a convention and is not enforced by JavaScript itlf. As far as is concerned, $ and _ are just ordinary letters of the alphabet.
再次注意,与$⼀样 , _的使⽤仅是约定,并⾮由JavaScript本⾝强制执⾏。 就⽽⾔, $和_只是字母表中的普通字母。
Of cour, this special treatment of $ and _ applies only within JavaScript itlf. When you test for alphabetic characters in the data, they are treated as special characters no different from any of the other special characters.
当然,对$和_的特殊处理仅适⽤于JavaScript本⾝。 在数据中测试字母字符时,它们被视为特殊字符,与其他任何特殊字符没有区别。javascript 符号