On 21 July 2015 at 08:14, Samuel Hapák <[email protected]> wrote:
> I have written proposal to allow extend standard behavior of object > destructuring: > > https://github.com/vacuumlabs/es-proposals/blob/master/extensible-destructuring.md > > Main idea is, that currently object destructuring is useless for people > who use Map or Immutable.Map (https://facebook.github.io/immutable-js/) > as their main data structure. > > This would allow authors of libraries to create map like structures that > would support destructuring. It extends the language in a similar way > iterator does. > > The main idea is, that if object defines `Symbol.get` method, it gets used > to access properties of object instead of `[]` when destructuring. > > What do you think? > People reading code will (rightfully) expect destructuring to be syntactic sugar for property access. I don't think it's worth breaking that equivalence. If you want user-defined patterns then they should be syntactically distinct from existing forms. Also, destructuring patterns are meant to match, and be the logical inverse of, literal syntax. Consequently, from my perspective at least, extensible destructuring would require first introducing extensible literal syntax in a symmetric manner. I think it would be unnecessarily surprising if for random patterns they didn't match up (worse, if you cannot even tell the meaning syntactically, but it depends on whatever object you happen to get). /Andreas
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

