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

Spread operator within ternary operator #478

Closed
lewispham opened this Issue Mar 16, 2016 · 6 comments

Comments

Projects
None yet
5 participants
@lewispham

lewispham commented Mar 16, 2016

I think it would be nice to be able to use spread operator like this:

var x = [1,2];
var y = [];
y.push(x instanceof Array ? ...x : x);
@getify

This comment has been minimized.

Show comment
Hide comment
@getify

getify Mar 16, 2016

Contributor

Feature proposal discussions belong on es-discuss.

Contributor

getify commented Mar 16, 2016

Feature proposal discussions belong on es-discuss.

@leobalter

This comment has been minimized.

Show comment
Hide comment
@leobalter

leobalter Mar 16, 2016

Member
var x = [1,2];
var y = [];
y.concat(x);
Member

leobalter commented Mar 16, 2016

var x = [1,2];
var y = [];
y.concat(x);
@topaxi

This comment has been minimized.

Show comment
Hide comment
@topaxi

topaxi Mar 16, 2016

See leobalters version, if your usecase needs push you can use:

var x = [1,2];
var y = [];
y.push(...Array.isArray(x) ? x : [ x ]);

topaxi commented Mar 16, 2016

See leobalters version, if your usecase needs push you can use:

var x = [1,2];
var y = [];
y.push(...Array.isArray(x) ? x : [ x ]);
@lewispham

This comment has been minimized.

Show comment
Hide comment
@lewispham

lewispham Mar 16, 2016

@leobalter Very nice suggestion if I don't mind creating a new array.

lewispham commented Mar 16, 2016

@leobalter Very nice suggestion if I don't mind creating a new array.

@lewispham

This comment has been minimized.

Show comment
Hide comment
@lewispham

lewispham Mar 16, 2016

@topaxi It looks like a workaround rather than an official method for the case. Also, I personally think it's a bit less readable.

lewispham commented Mar 16, 2016

@topaxi It looks like a workaround rather than an official method for the case. Also, I personally think it's a bit less readable.

@bterlson bterlson closed this Mar 17, 2016

@bterlson

This comment has been minimized.

Show comment
Hide comment
@bterlson

bterlson Mar 17, 2016

Member

Not the appropriate venue for this discussion.

Member

bterlson commented Mar 17, 2016

Not the appropriate venue for this discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment