Function constants for Identity and No-op

Andrea Giammarchi andrea.giammarchi at gmail.com
Wed Aug 10 16:41:29 UTC 2016


Kevin that "from somewhere else" has same problems cross-realm `instanceof`
would have, you can't always trust that and if you want to map identities
just do it instead of adding extra code ;-)

On Wed, Aug 10, 2016 at 5:24 PM, Kevin Reid <kpreid at google.com> wrote:

> [no quotes because I'm not replying to anyone in particular]
>
> An advantage that has not been mentioned yet, of having a canonical
> function instance for particular behaviors, is that it allows for some
> library-level optimization by being able to know what a function does
> (which is otherwise opaque). For a simple example:
>
> SomeKindOfImmutableCollection.prototype.map = function (f) {
>     if (f === Function.IDENTITY) {
>         return this;
>     }
>     ...build a new collection with f applied to elements and return it...
> };
>
> Of course, it would be silly to write coll.map(Function.IDENTITY), but a
> caller might be passing the function from somewhere else.
>
> (I only intend to point out this one benefit, not to claim it justifies
> the feature entirely.)
>
> _______________________________________________
> 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/20160810/ba6244c6/attachment.html>


More information about the es-discuss mailing list