What is the meaning of “$” sign in JavaScript

后端 未结 7 2165
无人共我
无人共我 2020-11-22 10:54

In the following JavaScript code there is a dollar ($) sign. What does it mean?

$(window).bind(\'load\', function() {
    $(\'img.protect\').pro         


        
7条回答
  •  天涯浪人
    2020-11-22 11:48

    Your snippet of code looks like it's referencing methods from one of the popular JavaScript libraries (jQuery, ProtoType, mooTools, and so on).

    There's nothing mysterious about the use of $ in JavaScript. $ is simply a valid JavaScript identifier.

    JavaScript allows upper and lower letters, numbers, and $ and _. The $ was intended to be used for machine-generated variables (such as $0001).

    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.

提交回复
热议问题