-
Notifications
You must be signed in to change notification settings - Fork 2k
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 Request: "Don't care" parameters #3449
Comments
Perhaps a coding convention is sufficient: doStuffAndCall (x, xx, data) ->
... Another option: doStuffAndCall ->
data = arguments[2]
... |
Duplicate parameter names (as |
The problem still exists. You're forced to name parameters you won't reference in the function body. |
There’s always the old “destructure into nothing” trick: doStuffAndCall ([], [], data) ->
...
# alternatively:
doStuffAndCall ({}, {}, data) ->
... @michaelficarra said in #1558 (comment):
Which seems to be true, and sane. Using So, IMO, this issue could be generalized into adding a single-item placeholder syntax for destructuring in general, which has been talked about before. The latest discussion being #3268 (comment), I believe. (Using the “destructure into nothing” trick feels like a hack to me, isn’t very intuitive, is a bit ugly and hasn’t got an ideal compilation.) |
Hmm, I see I didn't get around to it. But clearly |
We don't need a character for this. Just allow: |
Great idea, @satyr. It's clear to me what this means, as it resembles JavaScript's |
I thought about that, too, some time ago. I really like it. The reason I didn’t propose it was that I couldn’t make up my mind about when newlines are used instead of commas. [uninteresting, interesting] = foo
[
uninteresting
interesting
] = foo
[ , interesting] = foo
[
# ???
interesting
] = foo Should a comma be required in that last case? [
,
uninteresting
] = foo |
Another funny one is : should |
I was just going to bring that up, @Nami-Doc. Array and object literals (in CS and ES5) have both holes and elisions. If parameter lists are allowed to have holes, do they also have elisions? Basically, what is the arity of |
Another problem is that |
It'd have to. In case that feels too awkward, we could also allow
Should be same as |
I'd like to submit this feature for discussion and if I get positive feedback might take a crack at implementing it.
Occasionally I get into situations where I don't care about a particular parameter but I have to include it because I use a positional parameter to its right. The most obvious example is receiving data into a jquery event callback
I don't care about
e
at all but have to include it.In pattern-matching languages there's the catchall
_
pattern, so I would just use that, but I can't repeat it in a parameter list and with the prevalence of underscore/lodash it would actually be more confusing.I propose a new symbol that you can use in parameter lists to indicate you don't care something like
It could generate something like
doStuffAndCall(function(__1, __2, data) { ... })
What does everyone think?
The text was updated successfully, but these errors were encountered: