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

Allen Wirfs-Brock allen at wirfs-brock.com
Tue Nov 23 09:53:12 PST 2010


How is your example any different from if you had said:
   const foo=1;

In both cases, wrapping the declaration with a function changes its scope??

Allen

-----Original Message----- 
From: David Herman
Sent: Tuesday, November 23, 2010 9:24 AM
To: Dmitry A. Soshnikov
Cc: es-discuss at mozilla.org
Subject: Re: `static` keyword from C/C++ as own closured var declaration

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

Sure thing. Say you're writing some code with a constant value, and 
somewhere inside the code you use `static':

    var METERS_PER_SQUARE_KILOJOULE = 17.4;
    ...
    static foo = 1;
    ...
    f(foo, METERS_PER_SQUARE_KILOJOULE);

Now you decide you want to parameterize over the constant, instead of a 
fixed constant:

    function(metersPerSquareKiloJoule) {
        ...
        static foo = 1;
        ...
        f(foo, metersPerSquareKiloJoule);
    }

This change accidentally alters the scope of `foo'.

Dave

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



More information about the es-discuss mailing list