Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

javascript - JavaScript中“ $”符号的含义是什么(What is the meaning of “$” sign in JavaScript)

In the following JavaScript code there is a dollar ( $ ) sign.(在以下JavaScript代码中,有一个美元( $ )符号。)

What does it mean?(这是什么意思?) $(window).bind('load', function() { $('img.protect').protectImage(); });   ask by coderex translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your snippet of code looks like it's referencing methods from one of the popular JavaScript libraries (jQuery, ProtoType, mooTools, and so on).(您的代码段看起来像是来自一种流行的JavaScript库(jQuery,ProtoType,mooTools等)的引用方法。)

There's nothing mysterious about the use of $ in JavaScript.(在JavaScript中使用$并没有什么神秘之处。) $ is simply a valid JavaScript identifier.($只是有效的JavaScript标识符。) JavaScript allows upper and lower letters, numbers, and $ and _ .(JavaScript允许使用大小写字母,数字以及$_ 。) The $ was intended to be used for machine-generated variables (such as $0001 ).($打算用于机器生成的变量(例如$0001 )。) Prototype, jQuery, and most javascript libraries use the $ as the primary base object (or function).(原型,jQuery和大多数javascript库都使用$作为主要基础对象(或函数)。) 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 $ .(在这种情况下,您将使用jQuery而不是$ 。) In fact, $ is just a shortcut for jQuery .(实际上, $只是jQuery的快捷方式。)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...