Javascript:功能(_)是什么意思 [英] Javascript: what does function(_) mean

查看:130
本文介绍了Javascript:功能(_)是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在浏览bacon.js幻灯片:
http://raimohanska.github.io/bacon.js-slides/1.html



在第二个街区的第一行,它说:

pre $ 函数always(value){返回函数(_){返回值}}

function(_)是什么意思?

_ 只是一个函数参数 - 一个下划线是一些被程序员用来指示的约定忽略这个绑定/参数。



由于JavaScript没有进行参数计数检查,所以参数可能被完全省略。这种丢弃标识符在其他语言中更常见,但应考虑类似于 arr.forEach(function(_,i){..})的情况,其中 _ 表示不使用第一个参数。


I'm going through the bacon.js slide at: http://raimohanska.github.io/bacon.js-slides/1.html

In the 1st line of the 2nd block, it says:

function always(value) { return function(_) { return value } }

what does function(_) mean?

解决方案

In this case _ is just a function parameter - a single underscore is a convention used by some programmers to indicate "ignore this binding/parameter".

Since JavaScript doesn't do parameter-count checking the parameter could have been omitted entirely. Such a "throw-away" identifier is found more commonly in other languages, but consider a case like arr.forEach(function (_, i) {..}) where _ indicates the first parameter is not to be used.

这篇关于Javascript:功能(_)是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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