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

Why allow BindingPattern for BindingRestParameter #915

Closed
saambarati opened this issue May 12, 2017 · 7 comments
Closed

Why allow BindingPattern for BindingRestParameter #915

saambarati opened this issue May 12, 2017 · 7 comments

Comments

@saambarati
Copy link

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
Copy link
Author

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
Copy link
Contributor

syg commented May 12, 2017

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

@littledan
Copy link
Member

Cc @gsathya @caiolima

@caiolima
Copy link
Contributor

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
Copy link

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
Copy link
Author

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.

@Josh-Cena
Copy link
Contributor

I think this can be closed now? The final spec does not allow this syntax.

@ljharb ljharb closed this as completed May 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants