-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Don't care/anonymous parameter #5586
Comments
Just thinking aloud -- would |
I think so. Also, when commas stack up they get hard to count. Does the already-supported workaround of |
I agree with @sandersn. How about |
Maybe (_, __, x, ____) => x + 1 Would become (_, _, x, _) => x + 1 |
How about |
You could just use an empty binding pattern like arr.forEach(({}, index) => console.log(index));
arr.forEach(([], index) => console.log(index)); Since they are not disallowed (see tc39/ecma262#97), I'm inclined to close this unless there's a problem with that workaround. |
@DanielRosenwasser nice 👍 |
@DanielRosenwasser Sounds perfect. Would be nice if this special use case is documented though. |
@DanielRosenwasser Great, thanks. |
Many functional languages have a don't care parameter/variable that holds values not used by programs.
For example, a function like
Array.prototype.forEach
supplies three arguments to the callback. If the code only needs the second argument (index), it will still have to supply a name for the first one. The programmer can use a don't care parameter as the name of the first argument instead. This improves readability and avoids problem of accidentally shadowing.An additional keyword/comment may have to be introduced to define which string is used for this purpose as the traditional "
_
" happens to be used by the popular underscore library.This can also be extended to destructuring code.
The text was updated successfully, but these errors were encountered: