lexical for-in/for-of loose end

Andreas Rossberg rossberg at google.com
Mon Feb 6 07:44:48 PST 2012


On 6 February 2012 16:28, Brendan Eich <brendan at mozilla.org> wrote:
> Andreas Rossberg wrote:
>> Agreed. As long as we don't spec something weird, the extra effort for
>> implementations shouldn't be much more than that of an extra block
>> around the loop body.
>
> To take Allen's best shot and re-fire it, what do you think should happen
> here?
>
>  for (let i = 0, skip2 = function(){i++}; i < N; i++) {
>    foo();
>    if (bar())
>      skip2();
>  }

Pretty much the same as in

  let i_ = 0, skip2_ = function(){i_++};
  for (; i_ < N; i_++) {
    let i = i_, skip2 = skip2_;
    foo();
    if (bar())
      skip2();
  }

Probably not what the programmer expected, but as others have said,
it's a trade-off. This use case seems rare, rather obfuscated style
IMHO, and you can easily work around it. So probably not something you
want to be optimizing the language semantics for.

/Andreas


More information about the es-discuss mailing list