Why does Array.from accept non-iterable arraylikes?

Domenic Denicola domenic at domenicdenicola.com
Wed Jun 26 08:16:39 PDT 2013

From: Claude Pache

> 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.

I think this is not necessary for library cooperation or forward-compatible polyfilling. It may make it *nicer*, but it's not necessary, and I'd predict not even that helpful.

It's very easy for a community to standardize on a simple property name, whether it be `iterator` or `__iterator__`, without needing a blessed one handed down from TC39. The polyfill community can probably figure this out themselves. I can't see any polyfill maintainers rejecting a pull request to switch to a more widely-used name. And I don't think  there will be that many incompatible polyfill libraries out there anyway; in ES5 at least, we've seen one ascendant.

As for forward compatibility, this is pretty simple: just use `eval`. Icky and annoying, but [it works][1]. If you detect native iterator support, don't polyfill.

[1]: https://github.com/kriskowal/q/blob/7c1385197553bfbd5b8e5b3ea198edf71d112d6d/q.js#L316-L330

More information about the es-discuss mailing list