_(variable_name)在javascript中的含义是什么? [英] What does _(variable_name) mean in javascript?

查看:359
本文介绍了_(variable_name)在javascript中的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了以下javascript代码:

I came across the following javascript code:

this.removeEdge = function(source, target) {
  if(!_states[source]) return;

  var children = _states[source].children,
      index = _(children).indexOf(target);
  if(index !== -1) children.splice(index, 1);
};

_(儿童)是什么意思?

What does _(children) mean?

推荐答案

_ 是JavaScript中的有效变量标识符,理论上可以引用任何。使用带函数语法的 _(...)意味着 _ 是一个函数。

_ is a valid variable identifier in JavaScript, and could theoretically refer to anything. Using _(...) with function syntax implies that _ is a function.

也就是说,它通常由 underscore.js 库使用,但如果您正在查看缩小的代码,它很可能被用作另一个单字符变量名来保存文件大小。

That said, it is commonly used by the underscore.js library, however if you're looking at minified code, it's quite possibly being used as another single-character variable name to save on file size.

在你提供的例子中,似乎underscore.js用于将 children 作为集合处理,以便 indexOf 功能可以应用于集合。这与调用类似:

In your example provided, it appears that underscore.js is being used to treat children as a collection, so that the indexOf function can be applied to the collection. This would be similar to calling:

_.indexOf(children, target);

这篇关于_(variable_name)在javascript中的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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