Array iterator questions

Allen Wirfs-Brock allen at wirfs-brock.com
Sun Dec 2 11:47:17 PST 2012


On Dec 1, 2012, at 8:14 AM, Jason Orendorff wrote:

> 1. The current draft spec has Array.prototype.@@iterator() behaving like .values(), so:
> 
>     for (x of ["a"])
>         print(x);
> 
> would print the pair ["0", "a"].
> 
> The proposal had Array iterators producing values only by default. Why the change?
> 
> (It seems like it could be a typo, or it could be motivated by a desire for consistency across all collections. If the latter, Map should change, not Array.)

Note, there is a margin note on of 15.4.4.26 that hi-lites "items" and  says "Or should this be values".  There are a lot of notes like this in the draft.  They are requests for knowledgable reviews to check spec. language that  is uncertain for some reason.   
> 
> 2. According to 15.4.6.2.2, the iterators produced by Array.prototype.keys and .items will expose the index values as strings. Why strings? Don't numbers make more sense?
> 

It does that because array index keys are exposed as strings everywhere else.

There is no specific definition (that I can find) of the keys iterator for arrays in the wiki proposal.  There is only the general @iter.keys function which is defined in terms of for-in and hence returns string property keys.

However, I don't have any objection to return integer keys in this case.

Allen




More information about the es-discuss mailing list