Array#filter without callback function

Andrea Giammarchi andrea.giammarchi at gmail.com
Mon Nov 12 14:38:05 PST 2012


Asen, as mentioned what I meant is that I would sparse.filter(Object); once
if that's about having a repeated iteration.

This let you avoid the Boolean.bind(null, true) if that was the concern but
I have no idea about performances.

There are too many libraries to change in order to support this default
behavior, I guess, that's why I think is not worth it.

br


On Mon, Nov 12, 2012 at 1:29 PM, Andrea Giammarchi <
andrea.giammarchi at gmail.com> wrote:

> if it's about iterating you have forEach which does not iterate over non
> assigned indexes ... this looks like you want a new feature with an ES5
> method as filter is so that you can use an ES3 for loop after ...
>
> I mean, you have forEach, map, etc to iterate valid indexes, why would you
> need that?
>
>
> On Mon, Nov 12, 2012 at 1:24 PM, Asen Bozhilov <asen.bozhilov at gmail.com>wrote:
>
>> Hi,
>>
>> Array.prototype.filter could be used to convert sparse to dense array,
>> e.g.
>>
>> [1,,,,,2,,,,,3].filter(Boolean.bind(null, true)); //[1, 2, 3]
>>
>> Would be pretty straightforward if built-in filter could be called
>> without callback function and returns a dense array.
>> I guess the engines will optimize that and library authors could
>> gracefully iterate over index properties of arrays without checking for
>> existance.
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121112/5e52a8ed/attachment.html>


More information about the es-discuss mailing list