Function constants for Identity and No-op

Alexander Jones alex at weej.com
Wed Aug 10 19:29:42 UTC 2016


Those spellings don't help when trying to visually parse a bunch of code
which already largely consists of dense punctuation, though, IMO.

On Wednesday, 10 August 2016, Tab Atkins Jr. <jackalmage at gmail.com> wrote:

> On Wed, Aug 10, 2016 at 7:25 AM, Eli Perelman <eli at eliperelman.com
> <javascript:;>> wrote:
> > Now obviously it would be trivial for me to declare these constants in
> > userland code like I already do, e.g. `const NOOP = () => {}`, but in
> > projects where it's needed in several files, I'll have to put that in a
> > module or re-declare everywhere. This is not a huge inconvenience but
> > something that could easily allocated for in the language.
>
> Mark's argument (which I agree with) is that `x=>x` and `()=>{}` are
> good *spellings* of "identity function" and "noop function".  It's
> immediately obvious what they do; `obj.doCallback(()=>{})` is about as
> easy to understand as `obj.doCallback(Function.noop)`.  The ID
> function is even simpler - `obj.map(x=>x)` reads *extremely* well to
> me, equal or better than `obj.map(Function.id)`. If we were to reserve
> "id" and "noop" as bare global variables, I might agree that those
> were even better, but that's clearly out of the question.
>
> ~TJ
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org <javascript:;>
> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160810/743566cb/attachment-0001.html>


More information about the es-discuss mailing list