Function constants for Identity and No-op
Kevin Reid
kpreid at google.com
Wed Aug 10 16:24:19 UTC 2016
[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.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160810/815658d4/attachment.html>
More information about the es-discuss
mailing list