title: Why does JQuery require a global "window" object?
body: <p>I'm using <code>jsdom</code> together with <code>jquery</code> to scrape static web content in a Node.js application.</p>
  
  <p><code>jsdom</code> converts an HTML string to a DOM tree, including a <code>window</code> property. I found that I had to assign the DOM's <code>window</code> property to <code>global.window</code>, otherwise JQuery errors (saying that a global window object is required). Why is this required?</p>
  
  <pre><code>// Create DOM from HTML
  const JSDOM = require('jsdom').JSDOM;
  const jsDom = new JSDOM('&lt;html&gt;...&lt;/html&gt;')
  
  // Set up JQuery
  const { window } = jsDom;
  const { document } = window;
  global.window = window;
  const $ = global.jQuery = require('jquery');
  
  // Scrape content
  const tbl = $(document)
    .find('#table-id')
    .find('tr').each(function() {
      // Do something with $(this).html()
    })
  </code></pre>
  
  <p>Also, I have often seen this: <code>const $ = global.jQuery = require('jquery');</code> Why is <code>global.jQuery</code> required?</p>