I’m getting hung up on why Javascript globals are so dangerous, when a similar (?) behavior is in Ruby. When you make a variable, like foo, and it’s bound to main, isn’t that the same thing as having a Javascript variable bound to window?
I’m getting hung up on why Javascript globals are so dangerous, when a similar
Share
Actually, top-level locals in Ruby are not very much like global variables, because they cannot be accessed (using normal lexically-scoped references) from within methods or classes or modules.
And global variables are only a problem in systems that are large enough to have an object hierarchy or multiple modules. If you only use one scope, it doesn’t make any difference if it’s global or not.
So in a Ruby script, in a single file, that might do something like update your name server’s zone file, you (a) can’t access those top level locals except at the top level, and (b) it’s OK to use global variables in a tiny little program written at the global level.