In the Oct. ES6 draft you may noticed that there is an editor's comment
attached to each of sections 15.4.4.23-25. These are the definitions of the
items, keys, and values methods on array objects. The note says:"Need to
decide whether to allow an argument that requests sparse iteration". In other
words, should their signatures be:
Array.prototype.items(sparse = false)
Array.prototype.keys(sparse = false)
Array.prototype.values(sparse = false)
There is also code in the algorithm for ArrayIterator.prototype.next
(1415.4.6.2.2) that allow it to conditionally include or exclude sparse
elements in any iteration.
I believe that when we last discussed sparseness we concluded that the array
iterators would include sparse elements even though the existing
map/filter/etc. methods do not.
Adding the above parameter would make both options available, but with dense
iteration being the default.
So the question on the floor: is there any interest in having this variation
of array iteration in ES6?
Allen
On Nov 12, 2012, at 1:29 PM, Andrea Giammarchi 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 <[email protected]>
> 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
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss