Skip to content
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

Array destructuring #203

Closed
despairblue opened this issue Jul 21, 2015 · 3 comments

Comments

@despairblue
Copy link

commented Jul 21, 2015

Neither

let [route,] = 'post?id=1234'.split('?') // Unexpected trailing comma.

nor

let [route, ] = 'post?id=1234'.split('?') // Unexpected trailing comma. + A space is required after ','.

is allowed.

Whereas this

let [, parameters] = 'post?id=1243'.split('?')

is allowed.

Whether doing this is a good idea is probably disputable, but it is legal syntax.

@feross

This comment has been minimized.

Copy link
Member

commented Jul 21, 2015

standard is a code linter – the whole purpose is to prevent legal syntax that's confusing and/or likely to be a bug. :)

The first two examples let [route,] = ... and let [route, ] = ... are better written as let [route] = .... The comma does nothing, and standard disallows trailing commas in other situations, so this is consistent.

The last example let [, parameters] = ..., actually does something useful. It selects the second item in the array. Unless I'm missing something, I can't see a reason to disallow this.

@feross feross closed this Jul 21, 2015

@despairblue

This comment has been minimized.

Copy link
Author

commented Jul 21, 2015

@feross duh, yeah, I missed the forest for the trees while refactoring, my bad 😅

@feross

This comment has been minimized.

Copy link
Member

commented Jul 22, 2015

No worries!

@lock lock bot locked as resolved and limited conversation to collaborators May 11, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
2 participants
You can’t perform that action at this time.