Pure win: Array.from and Array.of

Dmitry A. Soshnikov dmitry.soshnikov at gmail.com
Sun Jul 10 04:09:25 PDT 2011


On 10.07.2011 14:27, Mike Shaver wrote:
> On Sun, Jul 10, 2011 at 6:06 AM, Dmitry A. Soshnikov
> <dmitry.soshnikov at gmail.com>  wrote:
>> The problem:
>>
>> Array(4).map(function(x) x * x); // [NaN, NaN, NaN, NaN]
> I think it actually produces just [ , , , , ], because map skips
> holes.  (If you see the NaN behaviour in FF, please file a bug.)
>

Sorry, did I wrote NaN? A "hole" of course (i.e. "nothing"), which is by 
[[Get]] is displayed as `undefined` in Firebug, or just as just ,,,, 
with toString. Anyway, the issue is in its behavior.


> If I hadn't made map skip holes, then the fill pattern would be simple enough:
>
> Array(4).map(function (_,x) x * x);
>

It's in particular case, you try to multiply indices, which in current 
implementation of `map` anyway gives unfortunately nothing.

Dmitry.


More information about the es-discuss mailing list