Array comprehension syntax

Jeff Walden jwalden+es at MIT.EDU
Mon Sep 14 11:49:43 PDT 2009


On 13.9.09 11:56 , Olav Kjær wrote:
> While experimenting with code-completion for ECMAScript I noticed a
> limitation with array comprehension syntax.
> The syntax as proposed (and implemented in Mozilla) has the output
> expression before the loop and filter:
>
>      [i.toString() for each (i in [1,2,3]) if (i != 2)]
>
> The problem is that the variable i in the output expression is defined
> by code to the right of it.

How do you address the following function?

> function foo()
> {
>   i = 3;
>   var i;
>   return i;
> }

Or this one?

> function foo()
> {
>   try
>   {
>     var i = 2;
>     throw i;
>   }
>   catch (e)
>   {
>     return i;
>   }
> }

Name before declaration is a problem already posed by the existing language syntax, isn't it?

Jeff


More information about the es-discuss mailing list