-
Notifications
You must be signed in to change notification settings - Fork 48
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
Proposal: Object naming when using object destructuring #86
Comments
Wouldn't it be possible to just use subdestructuring?
And for assignment:
if baz is out of scope, we could use:
|
I actually like this idea better. |
To clarify, convert the current syntax for subdestructuring: from and the newly introduced named destructuring syntax: from |
How is giving subdestructuring and |
It's actually not so much a different behaviour, it's treating the If it doesn't exist in the local scope, it gets created. If used with Right now, |
Maybe it would be better with example :
would give
|
That example doesn't make sense:
|
Hm. Current behaviour :
Proposed behaviour :
Here, a can get modified a lot before coming to the statement Anyways, the fact that using |
How does this behavior relate to this issue? It seems entirely different proposal to me.
The only difference between |
Precisely. What is being suggested here is that instead of having a Which has the implication of having the As for the function arguments, just being in the arguments creates the variable in the local scope, so not much would have to change. Another rationale for this request is that for now, using destructuration with |
And when doing |
It's not:
In fact, it can't be a parameter-only feature; destructuring in parameters is merely an extension of normal assignment:
For the reason I said above, this has to be:
Again, not if you have a variable assignment in it:
|
With the proposed syntax, you couldn't automatically sub-destructure a function argument into an outer variable, like in your example, but I think that's a good thing.
I see, but why don't we make it into a variable assignment? |
What about methods like
I don't see the point. |
Yeah, that's tricky, especially with The point would have been to have a more intuitive syntax for |
I think it's about elegance. Honestly,
Yes. But then again, the |
Also, how would you achieve:
? |
You don't anymore. Alright. You win. :) |
As seen in another issue, the problem right now is that when using object destructuring in function arguments, it is impossible to access the base object (which is named
_arg
,_arg2
,_arg3
at the moment).The proposal is the following :
( { foo, bar } : baz, ... ) ->
wherebaz
replaces_arg
.Ideally, it should also work for assignment ;
{ argv } : optimist = require \optimist
The text was updated successfully, but these errors were encountered: