下划线作为JavaScript变量? [英] Underscore as a JavaScript variable?

查看:91
本文介绍了下划线作为JavaScript变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这篇文章 Nick Craver 提供了他使用的答案:

In this post, Nick Craver provided an answer in which he used:

function(_, id)

此代码在使用之前不会将下划线声明为变量。我在谷歌和此处的搜索仅指向使用下划线作为前缀的引用,而不是作为变量本身。它有什么作用?我喜欢尼克的解决方案,但这让我感到困扰。

This code doesn't declare the underscore as a variable before using it. My search on google and on here only points to references to the use of the underscore as a prefix., not as the variable itself. What does it do? I like the solution by Nick but that bit bothers me.

推荐答案

我看到下划线用于表示变量是一个不关心变量。这意味着它无关紧要,根本不使用。

I've seen the underscore used to denote that the variable is a "don't care" variable. It means that it doesn't matter and isn't used at all.

在你指出的情况下,它被用来表示他的函数有两个参数,但他只需要第二个参数。

In the case you pointed out, it was used to signify that his function had two arguments, but he only needed the second one.

这篇关于下划线作为JavaScript变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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