ES6 draft, Rev20 is now available

Allen Wirfs-Brock allen at wirfs-brock.com
Wed Oct 30 11:28:33 PDT 2013


On Oct 30, 2013, at 10:51 AM, Boris Zbarsky wrote:

> On 10/30/13 7:57 AM, Anne van Kesteren wrote:
>> On Tue, Oct 29, 2013 at 4:50 PM, Allen Wirfs-Brock
>> <allen at wirfs-brock.com> wrote:
>>> Spread now requires an Iterable rather than an array-like
>> 
>> This is different from how sequence<T> behaves in IDL. (It uses array-likes.) :/
> 
> We could change that if we change all DOM arraylikesto be iterables (which they already are, I suspect).

All that is needed is to add an @@iterator method whose definition is identical to http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.prototype.values 
ArrayIterator objects (http://people.mozilla.org/~jorendorff/es6-draft.html#sec-array-iterator-object-structure ) will work fine with any Array-like objects.  But note that ES6 Rev20 has simplified them from what is shown at this link.

> 
> The biggest compat issue will be cases that pass { "length": 1, 0: "x" } to a sequence<DOMString> or something, but do people do this in practice?

Those are the sort of objects, that we decided to explicitly exclude from spread and for-of.  We could wrap an ArrayIterator around any object in those contexts that didn't have a @@iterator.  But that would mean that all objects would default to array-like iteration in those contexts.  When we discussed this we decided it is more likely that attempting to spreading or iterating over a object without a @@iterator is indication of a program bug.  So we throw on it.

For something like { "length": 1, 0: "x" }, one way to make it iterable would be { "length": 1, 0: "x" , [Symbol.iterator]: [].values}}


Allen


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


More information about the es-discuss mailing list