I was reading the following analysis from David Mark about the js framework "Sencha": https://gist.github.com/3279190 and in there he states...
What they wanted was a global variable, but they ended up with is a property of the Global Object. According the specifications and (and implementation history) there are enough differences between the two that care is required not to mix them up (as is done here).
...but as far as I was aware there wasn't any difference between var my_global = 123;
and (in a browser environment) window.my_global = 123;
(in that example I assumed the environment was a browser - hence the use of window
, but I could have just used this.my_global
instead as obviously the Global Object would be different when run in different environments).
But ignoring that minor discrepancy is there a difference between assigning a property to the Global Object and creating a global variable? I thought not, and that creating a global variable was just another way to assign a property to the Global Object.
I believe there can be an issue in some browsers if they had an element with an id of "my_global" then apparently that can cause problems with JavaScript referencing the right thing, but I'm not sure how/what causes that problem (e.g. does assigning a property to the Global Object cause the element id issue to occur, or is it declaring a global variable that causes the element id issue?)
Can someone clarify this for me please?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…