title: Why isn't my JavaScript function able to access global-scope functions/variables defined in my other .js files?
body: <p>I wrote a script like that:</p>
  
  <pre><code>NS.load = function(src) {
      var script = document.createElement("script").setAttribute("src", src);
      document.getElementsByTagName("head")[0].appendChild(script);
  }
  </code></pre>
  
  <p>It loads files but I can't reach functions and variables defiened in other files. </p>
  
  <pre><code>//js/main.js
  var qux = {name: "name"};
  NS.load("js/foo.js");
  
  //js/foo.js
  alert(qux.name); //undefined variable
  </code></pre>
  
  <p>But if I define qux like this:</p>
  
  <pre><code>window.qux = {name: "name"};
  </code></pre>
  
  <p>I can reach qux variable in other modules. As far as I know all globals are already a member of window object. So why I have to define variables like this. Could you offer another method?</p>
  
  <p>Thanks.</p>