iterate and enumerate trap signature inconsistency
Tab Atkins Jr.
jackalmage at gmail.com
Sun Sep 2 12:37:59 PDT 2012
On Sun, Sep 2, 2012 at 11:13 AM, David Bruant <bruant.d at gmail.com> wrote:
> Hi,
>
> 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.
>
> 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.
The difference in signatures is intentional, though I don't know how
required it is.
> 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?
A generator is a special kind of function that, when called, returns
an iterator over its own yield values.
~TJ
More information about the es-discuss
mailing list