@@iterator in arguments object

Axel Rauschmayer axel at rauschma.de
Sun Dec 23 19:49:09 PST 2012


Thanks. The first `let` should be a `const`.

On Dec 24, 2012, at 4:47 , Brandon Benvie <brandon at brandonbenvie.com> wrote:

> That is an excellent solution!
> 
> 
> On Sun, Dec 23, 2012 at 10:46 PM, Axel Rauschmayer <axel at rauschma.de> wrote:
> How about the following solution?
> 
>     let missingArgument = {}; // or a symbol
>     function reduce(callback, initial = missingArgument){
>         let startIndex;
>      
>         if (initial === missingArgument) {
>             initial = this[0];
>             startIndex = 1;
>         } else {
>             startIndex = 0;
>         }
>      
>         ...etc...
>     }
> 
> On Dec 24, 2012, at 3:32 , Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
> 
>> On Dec 23, 2012, at 5:35 PM, Brandon Benvie 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...
>>>    }
>>> 
>> 
>> the way I would express this example  is:
>> 
>> function reduce(callback, ...rest){
>>  var current, index;
>>  if (rest.length > 0) {
>>        index = 0;
>>        current = rest[0];
>>      } else {
>>        index = 1;
>>        current = this[0];
>>      }
>>  ...etc...
>> }
>> 
>> which seems to exactly express the intent
> 
> -- 
> Dr. Axel Rauschmayer
> axel at rauschma.de
> 
> home: rauschma.de
> twitter: twitter.com/rauschma
> blog: 2ality.com
> 
> 

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

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


More information about the es-discuss mailing list