Why does Array.from accept non-iterable arraylikes?
allen at wirfs-brock.com
Tue Jun 25 10:33:13 PDT 2013
On Jun 25, 2013, at 10:19 AM, Anne van Kesteren wrote:
> On Tue, Jun 25, 2013 at 4:58 PM, Jason Orendorff
> <jason.orendorff at gmail.com> wrote:
>> On Tue, Jun 25, 2013 at 10:42 AM, Sam Tobin-Hochstadt <samth at ccs.neu.edu> wrote:
>>> My recollection is that we chose to make `iterator` a symbol because
>>> we worried about taking the name "iterator" on lots of existing
>> What kind of existing code would be a problem?
>> Firefox added Array.prototype.iterator a year ago. It has shipped in
>> the release browser, and it's been fine.
> E.g. HTMLCollection has named getters. Making it iterable without
> breaking compatibility would be great.
This design discussion really wasn't just about iterator. In ES6 we have various property keys that are hooks deeply into either the semantics of core language features: @@create, @@hasInstance, @@ToPrimitive, @@iterator, @@toStringTag, @@isRegExp.
Anyone plugging into these hooks really should be intentional about what they are doing. Accidentally doing so my poor name choice may mot be disastrous but it is likely to be dificult to debug. Using a symbol for these properties greatly reduces the likelihood of such an accident.
We could make an exception for iterator, but why? That just introduces an inconsistency in the design.
More information about the es-discuss