return when desugaring to closures

David-Sarah Hopwood david.hopwood at
Sun Oct 12 19:55:28 PDT 2008

YR Chen wrote:
> On Sun, Oct 12, 2008 at 7:34 PM, David-Sarah Hopwood <
> david.hopwood at> wrote:
>> So why are we arguing about whether lambdas should be allowed without
>> braces, when the direction being taken for the rest of the language
>> is to make the braces mandatory around all forms that can potentially
>> declare variables?
> What "rest of the language" are you talking about? |if|, |while|, and |for|
> do not require braces and thus do not necessarily create block scopes.

|if|, |while|, |do..while|, |for|, and |with| *do* necessarily create block
scopes. Their bodies are always scopes regardless of whether they have
braces around them, even in ES3. (When the body is a statement that does not
introduce any variables, then whether a scope is created isn't observable,
and so we might as well consider them as creating a scope, for regularity.)

In ES3.1, this will mean that they normally require braces whenever a
body can introduce variables. There are two classes of exceptions,
shown by these examples:

  a) while (...) foo: var x = ...;
  b) while (...) for (var x = ...; ...; ...) {}

I think these are bugs. a) can certainly be disallowed. There might
possibly be existing code that is relying on b), confusing though it
is, but it can be disallowed in strict mode at least.

David-Sarah Hopwood

More information about the Es-discuss mailing list