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

Why allow BindingPattern for BindingRestParameter #915

Open
saambarati opened this Issue May 12, 2017 · 6 comments

Comments

Projects
None yet
5 participants
@saambarati

saambarati commented May 12, 2017

I'm looking at this spec text:
https://tc39.github.io/proposal-object-rest-spread/#Rest
and
https://tc39.github.io/proposal-object-rest-spread/#Rest-RuntimeSemantics-RestBindingInitialization

Why not only allow an identifier for rest?

For example, I think this code is too difficult to understand (and has little real world value):

let {[a]: b, ...[c]} = expr;

What does this even do? Not what I would've expected it to.

I think I finally understand that it's something like this (with a lot of hand waiving):

let tmp1 = a.toString();
let b = expr[tmp1];
let tmp2= { ... expr - tmp1 properties }  ;
let [c] = tmp2;
@saambarati

This comment has been minimized.

Show comment
Hide comment
@saambarati

saambarati May 12, 2017

An example of JS that expresses why I think this is crazy:

Object.prototype[Symbol.iterator] = function() { console.log('foo'); return {next: function() { console.log('baz'); return {done:true}}}}
let {...[baz]} = {foo:20}

saambarati commented May 12, 2017

An example of JS that expresses why I think this is crazy:

Object.prototype[Symbol.iterator] = function() { console.log('foo'); return {next: function() { console.log('baz'); return {done:true}}}}
let {...[baz]} = {foo:20}
@syg

This comment has been minimized.

Show comment
Hide comment
@syg

syg May 12, 2017

Member

@anba has raised a similar point here: tc39/proposal-object-rest-spread#43

Member

syg commented May 12, 2017

@anba has raised a similar point here: tc39/proposal-object-rest-spread#43

@littledan

This comment has been minimized.

Show comment
Hide comment
@littledan
Member

littledan commented May 15, 2017

@caiolima

This comment has been minimized.

Show comment
Hide comment
@caiolima

caiolima May 15, 2017

I don't think it's a good idea since we will not be consistent with Array Rest spec that allows recursively rest operations. IMHO it could bring confusion against intuitive usage of rest operations.

BTW, I think it's a good idea discuss this topic into tc39/proposal-object-rest-spread#43 since it is not part of spec yet.

caiolima commented May 15, 2017

I don't think it's a good idea since we will not be consistent with Array Rest spec that allows recursively rest operations. IMHO it could bring confusion against intuitive usage of rest operations.

BTW, I think it's a good idea discuss this topic into tc39/proposal-object-rest-spread#43 since it is not part of spec yet.

@peey

This comment has been minimized.

Show comment
Hide comment
@peey

peey May 31, 2017

Do note the functional differences between let {...{a}} = expr and let {a} = expr

The first example would only set a only if a is expr's own property, but the second example is equivalent to a = expr.a.

Though it does get redundant after one level of nesting, I don't see much point in let {...{...{a}}} = expr

peey commented May 31, 2017

Do note the functional differences between let {...{a}} = expr and let {a} = expr

The first example would only set a only if a is expr's own property, but the second example is equivalent to a = expr.a.

Though it does get redundant after one level of nesting, I don't see much point in let {...{...{a}}} = expr

@saambarati

This comment has been minimized.

Show comment
Hide comment
@saambarati

saambarati May 31, 2017

What do you mean by “only set a”? “a” will end up as not TDZ after both statements execute.

(FWIW, I understand there are other semantic differences in other ways to. Performing GetOwnPropertyNames is observable.)

Having a semantic difference isn’t a good enough reason to be in the language.

saambarati commented May 31, 2017

What do you mean by “only set a”? “a” will end up as not TDZ after both statements execute.

(FWIW, I understand there are other semantic differences in other ways to. Performing GetOwnPropertyNames is observable.)

Having a semantic difference isn’t a good enough reason to be in the language.

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