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

Ingvar von Schoultz ingvar-v-s at comhem.se
Wed Jul 30 15:17:44 PDT 2008

Ingvar von Schoultz wrote:
> 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.

Int this splashing out of { }, function declarations are
a special case. Although implementations differ, I think
{{ }} could serve as an opt-in where they become specified
to follow clear rules.

In my opinion the most useful rules would be:

The name is visible in the entire space between the nearest
surrounding {{ }}. Usually it's also callable in that entire
space, but there are a few exceptions.

If you put the declaration in a sequential construct,
for example under if(), then at the {{ you can't call it
(it's |undefined|), and it becomes callable only from the
sequential construct and onward. If there is a { at the
beginning of the sequential construct, the function becomes
callable from the { and onward.

If you make more than one declaration with the same name,
this makes all the declarations of that name sequential.
Then at {{ you can't call any of the versions of the
function (again |undefined|). Each version becomes callable
at the spot of declaration.

In all other cases the function is callable in the entire
space between {{ }}.

(This is not intended as an exhaustively detailed description,
just an overview.)

(The rules will have to be changed a little if let declarations
are allowed between {{ }}, or if allowing them there in a
future version should be possible. And reserving the possibility
might be a good idea -- who knows what people will want or
will invent. To allow that, the rules become slightly more

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