title: accessing global object when using requirejs
body: <p>I know it's not recommended to use the global object and the whole idea behind using AMD is to avoid using the global object. But for some legacy code, I have to define some stuff in the global object. Currently the code looks like this:</p>
  
  <pre><code>//example2.js
  define(function(){
    var globalObject = window;
    globalObject.x = ...
    globalObject.y = ...
  });
  </code></pre>
  
  <p>It works but hard coding the global object <code>window</code> doesn't look very nice and I'm curious to see if it is possible to remove it. When <code>define()</code> was not used, the code looked like this:</p>
  
  <pre><code>//example1.js
  x = ...
  y = ...
  </code></pre>
  
  <p>I know, I know you hate this code, but let's be to the point: how can the global variable be accessed in a structured manner inside the <code>define()</code> function in requirejs? I wish there was something like a hidden last parameter to the function that is passed to the <code>define()</code> like this:</p>
  
  <pre><code>//example3.js
  define(function(globalObject){
    globalObject.x = ...
    globalObject.y = ...
  });
  </code></pre>
  
  <p>Or even simpler: the <code>this</code> variable would point to the global object inside that function. For example:</p>
  
  <pre><code>//example4.js
  define(function(){
    this.x = ...
    this.y = ...
  });
  </code></pre>
  
  <p><strong>Note:</strong> I'm not sure about this last one. Investigating the <code>this</code> variable inside the function that is passed to <code>require()</code> says that it is equal to <code>window</code> which can be the answer to my question, but I haven't been able to find any documentation that mentions the context that the passed function is running. Maybe it is running in the context of the global variable after all?</p>