`static` keyword from C/C++ as own closured var declaration

Bga bga.email at gmail.com
Mon Nov 22 20:18:50 PST 2010


// 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  






More information about the es-discuss mailing list