有人可以用Javascript解释美元符号吗? [英] Can someone explain the dollar sign in Javascript?

查看:243
本文介绍了有人可以用Javascript解释美元符号吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有问题的代码在这里:

var $item = $(this).parent().parent().find('input');

变量名中美元符号的目的是什么,为什么不排除?

What is the purpose of the dollar sign in the variable name, why not just exclude it?

推荐答案

变量中的'$'对解释器来说没有什么特别之处,就像下划线一样。

A '$' in a variable means nothing special to the interpreter, much like an underscore.

从我所看到的,许多人使用 jQuery (这是你的示例代码看起来像对我来说,倾向于为包含带有$的jQuery对象的变量添加前缀,以便它们易于识别,而不会与整数相混淆。

From what I've seen, many people using jQuery (which is what your example code looks like to me) tend to prefix variables that contain a jQuery object with a $ so that they are easily identified and not mixed up with, say, integers.

美元符号函数jQuery中的 $()是一个经常使用的库函数,因此需要一个简短的名称。

The dollar sign function $() in jQuery is a library function that is frequently used, so a short name is desirable.

这篇关于有人可以用Javascript解释美元符号吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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