Pure functions in EcmaScript
waldemar at google.com
Wed Nov 28 12:25:02 PST 2012
On Wed, Nov 28, 2012 at 5:39 AM, Marius Gundersen <gundersen at gmail.com>wrote:
> On Wed, Nov 28, 2012 at 1:20 PM, Andreas Rossberg <rossberg at google.com>wrote:
>> many useful pure functions you could even write. For example, your
>> 'sum' function is not pure, because the implicit conversions required
>> by + can cause arbitrary side effects.
> 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.
You haven't addressed Andreas's point: Almost any function you write is
nonpure, including your sum example. As a fun exercise, go ahead and write
a pure version of your sum example.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the es-discuss