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 JavaScript, a function allows you to define a block of code, give it a name and then execute it as many times as you want. A JavaScript function can be defined using function keyword.
The function* declaration ( function keyword followed by an asterisk) defines a generator function, which returns a Generator object.
It's usually used to work around a quirk in the JavaScript syntax. This gives a syntax error: function() { }(); It's read as a function declaration (like function foo () {} ), rather than a function expression.
Updated on July 03, 2019. The dollar sign ($) and the underscore (_) characters are JavaScript identifiers, which just means that they identify an object in the same way a name would. The objects they identify include things such as variables, functions, properties, events, and objects.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With