“$”是什么意思?登录JavaScript [英] What is the meaning of "$" sign in JavaScript
问题描述
在以下JavaScript代码中,有一个美元( $
)符号。这是什么意思?
In the following JavaScript code there is a dollar ($
) sign. What does it mean?
$(window).bind('load', function() {
$('img.protect').protectImage();
});
推荐答案
您的代码片段看起来像是从一个引用方法流行的JavaScript库(jQuery,ProtoType,mooTools等)。
Your snippet of code looks like it's referencing methods from one of the popular JavaScript libraries (jQuery, ProtoType, mooTools, and so on).
使用 $ $ c并不神秘$ c>在JavaScript中。
$
只是一个有效的JavaScript标识符。
There's nothing mysterious about the use of $
in JavaScript. $
is simply a valid JavaScript identifier.
JavaScript允许使用大写和小写字母,数字和 $
和 _
。 $
旨在用于机器生成的变量(例如 $ 0001
)。
JavaScript allows upper and lower letters, numbers, and $
and _
. The $
was intended to be used for machine-generated variables (such as $0001
).
Prototype,jQuery和大多数javascript库使用 $
作为主要基础对象(或函数)。他们中的大多数也有办法放弃 $
,以便它可以与另一个使用它的库一起使用。在这种情况下,您使用 jQuery
而不是 $
。事实上, $
只是 jQuery
的快捷方式。
Prototype, jQuery, and most javascript libraries use the $
as the primary base object (or function). Most of them also have a way to relinquish the $
so that it can be used with another library that uses it. In that case you use jQuery
instead of $
. In fact, $
is just a shortcut for jQuery
.
这篇关于“$”是什么意思?登录JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!