Array.prototype.reduce ( callbackfn [ , initialValue [ , thisArg ] ] )

Edward Lee edilee at mozilla.com
Sat Mar 21 00:48:19 PDT 2009

Right now [].reduce doesn't take an optional thisArg, so the callback
is always called with |null| for |this| per 9.c.ii.

The Array prototype object take an optional thisArg for every, some,
forEach, map, and filter; so it would be good to make reduce
consistent with the rest.

The new parameter list for Array.prototype.reduce would then be.. Array.prototype.reduce ( callbackfn [ , initialValue [ ,
thisArg ] ] )

Insert after step 4:
#. If thisArg was supplied, let T be thisArg; else let T be undefined.

For step 9.c.ii, replace:
"callbackfn with null as the this value" with..
"callbackfn with T as the this value"

Similarly, this should be applied to reduceRight as well: Array.prototype.reduceRight ( callbackfn [ , initialValue [
, thisArg ] ] )

The only remaining Array callback is sort, which could be updated as well: Array.prototype.sort ( comparefn [, thisArg ] )


More information about the Es-discuss mailing list