Why does Array.from accept non-iterable arraylikes?

Dean Landolt dean at deanlandolt.com
Wed Jun 26 08:02:43 PDT 2013


On Wed, Jun 26, 2013 at 6:23 AM, Claude Pache <claude.pache at gmail.com>wrote:

>
> Iterables are useful not only in for/of loops but also in otherwise
> polyfillable constructs; for example, in the Set constructor:
>
>     // Let `a` be a Set object
>     b = new Set(a) // copy the elements of `a` into a new Set
>
> Question: Will there be a standard way for obtaining the @@iterator symbol
> for use in JS code? If so, let say that it is called `GetIteratorSymbol()`;
> then in pre-ES6 environments, we could define:
>
>     function GetIteratorSymbol() { return '__iterator__' }
>
> and implement/polyfill the iteration protocol in both old and new
> environments, using `GetIteratorSymbol()` where @@iterator is needed. If
> that `GetIteratorSymbol()` function is readily available in a standard
> place, it will allow different libraries to cooperate.
>


This is very similar to what I suggesting yesterday, though perhaps a
little less noisy. I was beating around the Object.[get|set]IteratorOf bush
but something like Object.getIteratorKey would solve the polyfill interop
problem with just one addition to a system builtin. Perhaps
Reflect.getIteratorKey would be a better place.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130626/d3448443/attachment-0001.html>


More information about the es-discuss mailing list