Reduce context parameter

Rick Waldron waldron.rick at gmail.com
Mon Jan 7 15:41:03 PST 2013


On Monday, January 7, 2013, Andrea Giammarchi wrote:

> not always, only when thisArg is needed ... Array#reduce(cb,
> initialValue[, thisArg])
>
> if needed, arr.reduce(cb, undefined, obj) does not look that bad, IMHO
>

undefined is a valid initialVal and won't cause reduce to fallback to the
first item in the array (I'd that behaviour was desired). Effectively
changing this:

var array = [2,3,4];

array.reduce(cb.bind(ctx))

To:

array.reduce(cb, array[0], ctx);

Not worth it. In fact, it's not even clear now what that param is even
for...


var

Rick

>
> again, I m fine with current status ...
>
>
> On Mon, Jan 7, 2013 at 3:14 PM, Rick Waldron <waldron.rick at gmail.com>wrote:
>
>
>
> On Monday, January 7, 2013, Andrea Giammarchi wrote:
>
> thisArg could have been third optional argument leaving current
> implementation as it is but making thisArg possible, IMHO
>
>
> lucky me I don't use Array#reduce that much neither I need the thisArg so
> far so ... OK for me
>
>
> Sorry, but no—this would force user code to always provide an initialVal,
> even when it would prefer to use the first item the array—which is the
> default when initialVal is omitted.
>
> Rick
>
>
>
>
> On Mon, Jan 7, 2013 at 2:59 PM, Rick Waldron <waldron.rick at gmail.com>wrote:
>
>
>
> On Monday, January 7, 2013, Andrea Giammarchi wrote:
>
> Rick you know bind is that slow and it costs on GC if used massively ;-)
>
>
> This is not my problem, implementors should optimize. bind() would only
> occur once per method call.
>
>
>
> I use a lot the second argument in Array#extras and I feel Peter van der
> Zee here: reduce/Right should have had that too
>
>
> The initialVal argument is _optional_ and undefined is valid — how would
> you decide if what was passed should be initial value or thisArg?
>
> Rick
>
>
>
>
>
>
> br
>
>
>
>
>
>
> On Mon, Jan 7, 2013 at 1:10 PM, Rick Waldron <waldron.rick at gmail.com>wrote:
>
> I know this doesn't answer your question, but Function.prototype.bind
> makes thisArg obsolete.
>
> Regarding the origin story, there is some discussion here:
> https://mail.mozilla.org/pipermail/es-discuss/2008-June/006431.html
>
> Rick
>
>
> On Mon, Jan 7, 2013 at 3:56 PM, Andrea Giammarchi <
> andrea.giammarchi at gmail.com> wrote:
>
> I think to increase confusion with other Array#extras :D
>
> and since we have this specced as it is now, a third parameter for the
> context could add even more confusion later on <3
>
> I know, I should not have answered that ...
>
>
> On Sun, Jan 6, 2013 at 9:48 AM, Peter van der Zee <ecma at qfox.nl> wrote:
>
> Mostly out of curiosity; why do Array#reduce and reduceRight have no
> context parameter?
>
> - peter
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
>
>
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> h <https://mail.mozilla.org/listinfo/es-discuss>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130107/7cf30586/attachment.html>


More information about the es-discuss mailing list