Function constants for Identity and No-op

Eli Perelman eli at
Tue Aug 9 18:44:09 UTC 2016

I'm not sure if something like this has been proposed before, but I often
find myself declaring constants for the identity function and the no-op
function. I think it would be useful to have constants available on
Function containing these values. For example `Function.IDENTITY` and
`Function.NOOP`. Essentially these constants would map to:

Function.IDENTITY = (a) => a;
Function.NOOP = () => null; // or:
Function.NOOP = () => {};

These could then be used in places where non-user-controlled APIs need
default functions need to be executed, or as placeholders for default
values that may be executed before a function has been supplied. For

// third-party API requires a callback or throws, but no functionality
really needs to done:

// Function needs a default which *may* execute prior to having a different
one specified (contrived):
const action = (handler = Function.IDENTITY, value = 10) => handler(value);

Thoughts? Seems like something simple with positive value. Thanks!

Eli Perelman
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list