A simple translation of the scoping-block syntax sugar -- Was: Re: function hoisting like var

Ingvar von Schoultz ingvar-v-s at comhem.se
Tue Jul 29 16:42:56 PDT 2008

I'd like to summarize some clarifications and arguments.

I'm thinking of what it might be like if {{ }} should become
available in ES3.1.

=== Intuitive ===

The proposed {{ }} mean exactly the same thing as { } in C, Java etc.

If switching between languages causes you any difficulties, simply
use {{ }} everywhere in your ES3.1 code. This way you get the braces
that you're used to from C and Java, apart from a slightly different

Think of it as JavaScript having a small difference in brace notation
while the functionality is the same.

=== Control flow ===

In ES3 you can use { } for plain control flow, without any scoping.
This is very useful for small projects.

If this is not a good fit for your projects, it's still very useful
elsewhere. Please don't deprecate this functionality.

For more on the usefulness of this plain control flow, see:

=== Difference ===

If you want the full flexibility of using both {{ }} and { },
first decide which type of brace you want to use most in your
program. Stick with that almost everywhere. Make an exception
only when you have a clear and specific reason, because you
need the functionality of the other type.

This way your code will be consistent and readable.

You can view the {{ }} as containers for variables. Any variable
that you declare anywhere will simply splash out of any { } and
attach itself to the nearest surrounding {{ }}, becoming visible
in the entire space between them.

If you prefer a more low-level view, { } are plain jumps and
branches, and only {{ }} affect the scope chain.

=== Ugly ===

The proposed {{ }} will inevitably look horrible in emails if
you use a proportional font such as Times New Roman. Real code
is never displayed in such a font. Try a programmer's editor
with a suitable font and syntax coloring. It looks completely

If people still find it ugly, I hope a good alternative can be
found, because the functionality would be very useful.

=== Let declarations ===

There are existing implementations that support let.

My proposal is that /let declarations/ should be completely disabled
between {{ }}. This of course includes all { } that are nested between
{{ }}.

The only reason is simplicity, mainly for the script programmer.

Outside {{ }} they should be enabled, for compatibility and to satisfy
those who prefer the let and var combination.

Ingvar von Schoultz

------- (My quirky use of capitals in code comes from my opinion that
reserved and predefined words should all start with lowercase, and
user-defined should all start with uppercase, because this will easily
and elegantly prevent a host of name-collision problems when things
like programming languages are upgraded with new labels.)

More information about the Es4-discuss mailing list