On 11/22/10 20:18, Bga wrote:
// es3 way
(function()
{
   var x = 1;

   return function()
   {
     return ++x;
   }
})();

// current es6/SM1.8 way
let(x = 1) function()
{
   return ++x;
}

// "new" more readable sugar
function()
{
   static x = 1; // hello c/c++

   return ++x;
}

Implementation, when compiling source code, just collects 'static' vars
from scope and wraps current scope to closure scope with collected vars

This was already discussed at the September meeting.  Some interesting issues 
are:

- How far does "static" hoist?  One let-scope?  One block-scope?  One 
function-scope?   One class-scope?
- Refactoring by adding or removing a scope becomes quite error-prone.
- To avoid breaking refactoring, you'd need to allow "static static", "static static 
static", etc.
- In what scope do you look up the initializer expressions?  What if they 
reference variables that were shadowed in between the scope where they're 
actually present and the one into which they got hoisted?
- When do the initializers run?  What if it's a static const?
- What happens if you have two of the functions above, each trying to hoist its own 
"x" into the same scope?  Under which conditions do the x's stay separate, and 
under which ones do they become the same variable?

    Waldemar
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to