Why does Array.from accept non-iterable arraylikes?

Jason Orendorff jason.orendorff at gmail.com
Tue Jun 25 12:40:32 PDT 2013

On Tue, Jun 25, 2013 at 1:16 PM, Brandon Benvie <bbenvie at mozilla.com> wrote:
> On 6/25/2013 10:33 AM, Allen Wirfs-Brock wrote:
>> We could make an exception for iterator, but why? That just introduces an
>> inconsistency in the design.
> I think the motivation was to make it easier to polyfill,

The motivation is to make it *possible* to polyfill correctly in
existing browsers. The protocol and related library features are
useful even without syntactic support.

> but I don't think
> that argument holds for @@iterator. If you're attempting to polyfill
> iteration, then you have to polyfill both ends of it; you have to supply
> both the iterators as well as functions to consume those iterators (since
> you can't polyfill for-of). That means you have control over the protocol,
> and can opt to use something like "__iterator__".

That kind of polyfill would not support other code that produces or
consumes the protocol.


More information about the es-discuss mailing list