"I thought I understood that the
this.
keyword always specified the global variable/object?"
No. The value of this
depends on how a function is called and whether the function is in strict mode.
In the browser global variables are properties of the window
object, so use:
window.globalVariable = 7;
Sometimes this
is equal to window
, but often it is not. (I don't mean that to sound like this
just gets set randomly; there is a specific set of rules that apply.)
Note that if you find yourself needing to distinguish between global variables and local variables like this you might well be using too many global variables.