-
Notifications
You must be signed in to change notification settings - Fork 84
Should we forbid array patterns for rest-properties? #43
Comments
The RHS could be something with a |
@ljharb This feels like a weak argument in favor of this. I don't see how the rhs having Symbol.iterator would make any difference. I think the only use case would be setting Object.prototype[Symbol.iterator] to something. I don't think this is a real use case. It's really unintuitive and not what users expect. There would be nothing stopping us from adding it in the future if we found a real use case. It seems unwise to add it without a real one though. I also think we should forbid further object destructuring, e.g: (I also brought this up on the main tc39 issues: tc39/ecma262#915) |
Oh right, actually for object rest/spread, Symbol.iterator doesn't apply at all - it uses Object.assign semantics. |
(Setting things on Object.prototype, or any other prototype object, is a "real use case"; but it's moot because Symbol.iterator is irrelevant to this proposal) |
The semantics for something like this only effect an Object.prototype[Symbol.iterator] or something where Symbol.iterator ends up as part of the rest properties (if this is even allowed) |
Gotcha. That does seem weird. |
I agree that it seems weird as well. IMHO it makes sense syntactically, however I can't see a good use case that seems worth keeping it in the current proposal version. |
Just clarifying, I agree with array related topic, however I'm not in favor to allow just identifiers into rest destructuring. |
The conclusion in https://github.com/tc39/tc39-notes/blob/master/es8/2017-05/may-23.md#conclusionresolution-10 says that the consensus is to disallow both I'd prefer to avoid disallowing |
This was the consensus recorded in the minutes for the May 2017 TC39 meeting, following bug tc39#43
@ajklein I think I think the symmetry argument would be that we already allow: |
@saambarati It sounds like you're thinking of this from the perspective of a user wanting to accomplish some specific task (which is a totally reasonable way of thinking about things, I should say!), rather than from the direction of what each bit of syntax does, semantically. In the latter sense, the |
@ajklein I see what you're saying, and agree. The way I've been thinking about it is like: the context of where the Anyways, I'm not sure if we've made progress on deciding what to do here. I wasn't at the meeting, so I'm not sure exactly what was discussed. I find the argument of not allowing users of the language to introduce, except in the case of Proxy, unnecessary redundancy more compelling than doing something just so there is symmetry in the syntax. |
The argument (by Allen) that convinced me that we needed to address this at all (rather than just leaving it as a runtime error) was that this syntax might make sense for one of the additions we'll want to make in the future. For example, if we add a custom key iteration protocol (similar to What that means for Since |
@sebmarkbage thanks for the background and motivation. I do think it would be weird for |
It's not really useful to support
var {...[]} = {}
since Object.prototype doesn't have aSymbol.iterator
property. Maybe we should simply forbid array patterns in this position?The text was updated successfully, but these errors were encountered: