JavaScript中的$符号是什么 [英] What is the $ symbol used for in JavaScript
问题描述
我是JavaScript学习者,一直在研究此问题,但没有成功.除正则表达式外,JavaScript中的$
符号是什么?任何资源或与此有关的阅读将不胜感激. 谢谢.
I am a JavaScript learner and have been researching this matter, but with no success. What is the $
symbol used for in JavaScript besides regular expressions? Any resources or readings regarding this would be appreciated. Thanks.
推荐答案
这没什么特别的.
但是由于标识符名称中允许使用$
,因此许多Javascript库都将$
用作它们的中央"接口,或者至少用作访问其功能的快捷方式.
But because $
is allowed in identifier names, many Javascript libraries have taken to using $
as the "central" interface to them, or at least as a shortcut for accessing their functionality.
例如,如果您使用的是jQuery并说$("div")
,则这是对带有参数"div"的$
函数的调用.当您说$.post()
时,它将在$
对象上调用post
方法(JavaScript很不错,因为函数是一等对象).
For example, if you're using jQuery and you say $("div")
, this is a call to the $
function with argument "div". When you say $.post()
, it's calling the post
method on the $
object (Javascript is nice in that functions are first-class objects).
这篇关于JavaScript中的$符号是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!