Personally, I'm a huge fan of this proposal. It would integrate into the language the extremely frequent idiom of defining a pick/pluck like function. There is ample prior art in the form of Ramda's pick function <https://ramdajs.com/docs/#pick>.as well as `pluck` in RxJS.
In fact, this exact proposal was at one point included in the proposal for "extended dot notation", then removed in the interests of making making it more digestible. AFAICS the syntax is completely unambigious: ``` const pickName = .name; // equivalent to ({name}) => name [{id: 1, name: "Bob"}, {id: 2, name: "Sally"}].map(pickName ``` The only objection I can think of is that the leading dot is sometimes hard to see. I would have suggested using the hash mark--in fact, an early version of the exptended dot notation proposal did propose that--but now that has been taken by the private fields proposal, so unless we want to go in the direction of keywords or magic operator sequences we are reduced to using non-unary operators such as ^, so ``` const pickName = ^name; ``` On Fri, Jun 21, 2019 at 9:47 AM Simon Farrugia <simonfarrugi...@gmail.com> wrote: > New syntax will always look a bit odd at first until we get used to it. > > I sometimes find nested arrow functions a bit confusing to understand > where one function starts and where it ends particularly when they are one > liners. > This syntax is more concise and personally I find it more readable. > > Reasons for the leading dot notation is because I think it's intuitive and > also self explanatory: > 1) We just remove what is in common on both ends of the expression (like > simplifying an algebraic expression). > ``` > const getEmail = user => user.contacts.email; > ``` > 2) The leading dot indicates that the expression reads the property of an > object that is not statically defined. > ``` > const getEmail = .contacts.email; > ``` > _______________________________________________ > es-discuss mailing list > es-discuss@mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss