我需要在javascript变量名之前加一美元吗? [英] Do I need to put a dollar before variable names with javascript?

查看:123
本文介绍了我需要在javascript变量名之前加一美元吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

var formSubmitHandler = function (link, form) {

    //e.preventDefault();
    var $form = form;
    var val = $form.valid();
    var action = $(form).data('action');
    var entity = $(form).data('entity');

我需要var $ form = form这一行吗?我可以稍后再做var val = form.valid();?

Do I need the line "var $form = form"? Can I just later on do "var val = form.valid(); ?

这不是我的代码所以我想知道为什么开发人员在表单之前添加了$分配了吗?

It's not my code so I am wondering why the developer added the $ before the form and assigned it?

更新:

感谢您的所有回复。如果是一直说它只是表明它是一个jQuery变量然后我可以通过将函数参数更改为(link,$ form)来删除该行吗?

Thanks for all your replies. If as has been said it's just to indicate that it's a jQuery variable then could I just remove that line by changing the function parameters to (link, $form) ?

推荐答案

$ jQuery 基本上就是jQuery实例。

$ and jQuery are basically the jQuery instance.

很高兴理解 $(<在这里放置一些>)是一个jQuery函数调用, $ your_variable_name 只是一个带有美元的变量。

It's good to understand that $( < place something here >) is a jQuery function call and $your_variable_name is just a variable with a dollar.

有些人在自己的变量中使用 $ 表明它是一个jQuery对象。使用这个命名约定,你的源代码就是这样。

Some people use $ in their own variables to indicate that it is a jQuery object. With this naming convention, your source code would like this.

var formSubmitHandler = function (link, form) {
    var $form = $(form);
    var val = $form.valid();
    var action = $form.data('action');
    var entity = $form.data('entity');

这篇关于我需要在javascript变量名之前加一美元吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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