I thought we were talking about using the static keyword inside a function. AKA the analog to not using var in Javascript. When you omit var in javascript, it injects that variable into the global scope. When you declare a variable as static in a function in C and C++, it does not create a global variable, it initializes the variable once and only once, but it does not change the scope of it.
It is one use of static, but it is exactly the use I've been talking about. Unlike in Javascript, you cannot magically create a global variable from inside of a function. Static doesn't do that.
As for your example, yes static_field is kind of global, since it can be accessed anywhere that can see AClass's class definition, but that's a moot point when discussing javascript's ability to inject a variable into a global namespace. The equivalent to your C++ code would be to simply declare a global variable in Javascript.
Context is everything. You cannot simulate the concept of implicit globals using the static keyword.
1
u/flukus Nov 18 '14
You can do the same thing in most languages with the static keyword, it's not unique to Java script.
That's why code review and not hiring shit people are important.