Pure functions in EcmaScript

Andrea Giammarchi andrea.giammarchi at gmail.com
Wed Nov 28 08:24:53 PST 2012

I use the context argument quite a lot in order to be able to recycle those
functions as much as possible so `this` is needed in my case plus map and
filter do not necessary return a new value based on what's in the function.

"abc".split("").map(function(c){return this(c.charCodeAt(0) - 32)},
String.fromCharCode).join("") // ABC

whenever it's a dumb example or not, I don't see that function dangerous,
not serializable, or not pure

my 2 cents

On Wed, Nov 28, 2012 at 5:39 AM, Marius Gundersen <gundersen at gmail.com>wrote:
> Functions passed to the array methods map, reduce, filter, etc would be
> good candidates for pure/side-effect-free functions. These functions
> shouldn't alter any state; they should only return a new value based on the
> parameter they were sent.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121128/3b4f0b67/attachment-0001.html>

More information about the es-discuss mailing list