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

2008-07-30 Thread Ingvar von Schoultz
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 imple

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

2008-07-29 Thread Ingvar von Schoultz
The translation can be made simpler. First, define a unique value, to be returned when the end of the scoping block is reached. If done in JavaScript: var _EndOfBlock = {}; Then each {{ }} can be translated to this: var _ReturnValue = (function (arguments) { // Any gover

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

2008-07-29 Thread Ingvar von Schoultz
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

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

2008-07-29 Thread Ingvar von Schoultz
If the simple translation of {{ }} is used, any governing for(), while() or switch() must be moved inside the scoping function. A very simple, very minimalistic approach may be enough. for (var Name in Thing) {{ }} Name is locally contained inside {{ }} while Thing is outside. But

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

2008-07-29 Thread Ingvar von Schoultz
The simple translation of {{ }} that I posted yesterday needs an improvement. It must pass |this| and |arguments| to the scoping function. I still think it looks quite small and simple, and that it would be a very useful addition to the language. try { var _ReturnValue = (function (ar