“$”是什么意思?登录JavaScript [英] What is the meaning of "$" sign in JavaScript

查看:574
本文介绍了“$”是什么意思?登录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).

使用 $ 在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆