Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there any difference between a global variable and a property of the Global Object
    primarykey
    data
    text
    <p>I was reading the following analysis from David Mark about the js framework "Sencha": <a href="https://gist.github.com/3279190" rel="noreferrer">https://gist.github.com/3279190</a> and in there he states...</p> <blockquote> <p>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).</p> </blockquote> <p>...but as far as I was aware there wasn't any difference between <code>var my_global = 123;</code> and (in a browser environment) <code>window.my_global = 123;</code> (in that example I assumed the environment was a browser - hence the use of <code>window</code>, but I could have just used <code>this.my_global</code> instead as obviously the Global Object would be different when run in different environments). </p> <p>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.</p> <p>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?)</p> <p>Can someone clarify this for me please?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload