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

Dmitry A. Soshnikov dmitry.soshnikov at gmail.com
Tue Nov 23 01:16:37 PST 2010


On 23.11.2010 12:07, David Herman wrote:
> Allen suggested something like this in the September meeting. One issue people had with it was that it adds another violation of the equivalence between a statement<stmt>  and (function()<stmt>)(), which is a refactoring hazard. Put differently, if you have some code with "static" declarations in it, you can't wrap the code in a function body without breaking the code, which makes it brittle.
>

Can you give a small example (it's just interesting) -- to see the issue?

> Separate from that, I also don't really see how the idea really buys you all that much. The analogy to C is only so helpful, since C doesn't have nested functions (and static therefore always lifts to global scope), so mostly it just reads to me like a rather obscure way of saying "oops, I meant to bind this over there."
>

It seems to me too that such a way may bring a confusion to JS 
development. And I also agree that in C it was caused by the _issue_ of 
absence nested functions with lexical scope.

Dmitry.

> Dave
>
> On Nov 22, 2010, at 8:18 PM, 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
>>
>>
>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list