iterate and enumerate trap signature inconsistency
allen at wirfs-brock.com
Tue Sep 4 08:39:22 PDT 2012
On Sep 2, 2012, at 11:13 AM, David Bruant wrote:
> The enumerate (for..in loops) and iterate (for..of loops) traps have
> inconsistent signatures. The former needs an array of strings to be
> returns, the latter an iterator.
the current ES6 spec. draft uses internal methods, [[Enumerate]] and [[Iterate]]. The implementation of these methods for proxy objects (will, its not in the draft yet) call the corresponding handlers.
Both of the internal methods are spec'ed to return an object that implements the iterator interface (generator instances comply).
If you want a the set of enumerated/iterated items to be fixed before the start of a loop, the handler can always create a fixed collection of values and return an iterator over that.
> I would tend to be in favor of both returning an iterator to avoid
> allocating, filling & freeing memory in case of recurrent for..in/of
> loops on the object. It's also somewhat more aligned with the idea of a
> loop: if the loop contains a 'break' statement, in the array case, some
> memory is left unused, but in the iterator case, the iterator just stops
> being called if control gets out of the loop.
> By the way, what's the difference between an iterator and a generator?
> Would it make sense that both traps return a generator rather than an
> iterator? Why?
> es-discuss mailing list
> es-discuss at mozilla.org
More information about the es-discuss