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

More powerful destructuring #111

Open
nmn opened this issue Dec 1, 2014 · 3 comments
Open

More powerful destructuring #111

nmn opened this issue Dec 1, 2014 · 3 comments
Labels

Comments

@nmn
Copy link

nmn commented Dec 1, 2014

Spider already supports:

var [a, b] = [1, 2];
[a, ,b] = [1, 2, 3];
[a, b] = [b, a];

Spider also supports splats ...rest.

Spider should support the following (It may support some of these already):

var {a, b} = {a: 1, b: 2};
var {first: a, last: b} = {first: 1, last: 2};
var [a, b, ...rest] = [1, 2, 3, 4, 5];
var {a, b, ...rest} = {a: 1, b: 2, c: 3, d: 4}; // rest = {c:3, d:4}

Also in function parameters:

fn obj({x, y, z}, color){...}

// which is called like this:
obj({x: 1, y: 2, z: 3}, 'blue');

This would all be extremely useful in a lot of places, and are features that libraries like React will soon depend on. Most of these features are part of ES6. the ...rest in an object is not, but it is a proposal. JSX will be adding support for it anyway.

@alongubkin
Copy link
Owner

Spider already supports:

var {a, b} = {a: 1, b: 2};
var {first: a, last: b} = {first: 1, last: 2};

@nmn
Copy link
Author

nmn commented Dec 2, 2014

I suspected as much. So at the moment, Spider supports destructuring to the same level as ES6.

rest operator in objects, and destructuring in function params would be great. If however, you don't want to get ahead of ES6, that's a different matter.

@michaelstephendavies
Copy link
Contributor

+1

Destructuring should be allowed in all of these, too. I'm not sure which of these are already supported:

fn f([x, y]) { ... }
for [x, y] in [[0, 1], [2, 3], ...] { ... }
[ ... for [x, y] in [[0, 1], [2, 3], ...] ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants