Extensible destructuring proposal
Andreas Rossberg
rossberg at google.com
Tue Jul 21 18:16:13 UTC 2015
I think the example actually reveals a deeper issue with the motivation:
the desire to destructure maps like here is rooted in a category error.
Destructuring is designed to apply to objects from the program domain,
while maps are typically meant to encode data from the problem domain.
Or, in other words: destructuring is only useful when you know the keys at
programming time (i.e., statically). But if that is the case, there is
rarely a good reason to use a map.
/Andreas
On 21 July 2015 at 18:12, Domenic Denicola <d at domenic.me> wrote:
> Well, the spec says they are ordered, so I'm not sure where you're
> getting that from.
>
>
> *From:* Bergi <a.d.bergi at web.de>
> *Sent:* Jul 21, 2015 8:53 AM
> *To:* Domenic Denicola; es-discuss
> *Subject:* Re: Extensible destructuring proposal
>
> Domenic Denicola schrieb:
> > For maps you can just do
> >
> > ```js
> > const [[k1, v1], [k2, v2], ...rest] = map.entries();
> > ```
>
> The problem with this is that you would need to know the order of the
> keys in the map. Your code does only extract the "first" and "second"
> key-value pairs, allowing us to get the key values of them, but this
> syntax does not allow us to extract the value for a given key from
> somewhere in the map.
> Predictability is all fine, but I still consider maps to be inherently
> unordered.
>
> Bergi
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150721/f999a4dc/attachment-0001.html>
More information about the es-discuss
mailing list