Extensible destructuring proposal
Samuel Hapák
samuel.hapak at vacuumapps.com
Tue Jul 21 18:27:17 UTC 2015
> On 21.7.2015, at 17:19, Domenic Denicola <d at domenic.me> wrote:
>
> From: Samuel Hapák [mailto:samuel.hapak at vacuumapps.com]
>
>> Could you please explain it on example?
>>
>> Let’s say I have
>>
>> ```
>> let book = Map{author: {name: “John”, surname: “Doe”}, birthdate: “10-10-1990”};
>> ```
>>
>> How would you extract `birthdate`? How would you extract `name`?
>
> Your syntax here is invalid in at least four different ways.
> If this is still confusing, you may wish to turn to StackOverflow for clarification, instead of es-discuss.
I apologize for the syntax mistakes I made. I totally understand you receive tons of proposals from people who don’t bother to learn JavaScript. I understand that this pissed you off and I am sorry for that. My bad.
Here is the valid syntax:
```js
let book = new Map([['author', Map([['name', 'John'], ['surname', 'Doe']]), ['birthdate', '10-10-1990']]);
let book2 = new Map([['birthdate', '10-10-1990'], ['author', Map([['name', 'John'], ['surname', 'Doe']])]]);
```
Now, I wish to extract `birthdate` and `name`. I can't rely on the order of elements, because the code should accept any `book` that has same shape. Let's say, ordering of the items in the map is not the part of the contract. So, to clarify this, I want to write function that accepts `book` or `book2` and inside, it extracts `birthdate` and `name`. The code should work with both `book` and `book2`.
I feel, that your solution is unable to achieve this, but I can be mistaken.
Thanks!
Samuel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3589 bytes
Desc: not available
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20150721/ed67357c/attachment.p7s>
More information about the es-discuss
mailing list