@@iterator in arguments object

Rick Waldron waldron.rick at gmail.com
Sun Dec 23 18:22:55 PST 2012


On Sun, Dec 23, 2012 at 8:35 PM, Brandon Benvie
<brandon at brandonbenvie.com>wrote:

> Here's one of the examples that was sticking out in my mind earlier that
> Brendan's solution takes care of. Array.prototype.reduce requires that if
> the initial value isn't provided then the first value of the array is the
> initial value.
>
> Using rest:
>
>     function reduce(callback, ...initial){
>       var current, index;
>
>       if (initial.length) {
>         index = 0;
>         current = initial[0];
>       } else {
>         index = 1;
>         current = this[0];
>       }
>
>       ...etc...
>     }
>
>
> Using arguments.length:
>
>     function reduce(callback, initial){
>       var current, index;
>
>       if (arguments.length > 1) {
>         index = 0;
>         current = initial;
>       } else {
>         index = 1;
>         current = this[0];
>       }
>
>       ...etc...
>     }
>
>
>
> I guess using rest like that is not a bad way to solve it, though it's not
> saying what you mean but rather kind of hacking around the limitation.
> Either way, it's certainly possible to forgo using arguments to accomplish
> the goal.
>

In the case of reduce, the specification algorithm names an identifier in
the formal parameter list: initialValue, so what is preventing your
implementation from doing initial !== undefined?

Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121223/9c89ff7e/attachment-0001.html>


More information about the es-discuss mailing list