title: jsdom: Run a page's javascript functions
body: <p>I've been messing around with jsdom and I can't figure out how to run functions from the html page. For example, I've got a simple page like this:</p>
  
  <pre><code>&lt;html&gt;
    &lt;body&gt;
      Hello
    &lt;/body&gt;
    &lt;script&gt;
      function test() {
        document.write("Bye bye")
      }
    &lt;/script&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>And I'd like to execute the <code>test</code> function from jsdom. How do I go about doing this? I've tried simply calling the function, but node complains that it doesn't exist.</p>
  
  <pre><code>jsdom.env({
      url : "http://localhost:8000/test.html",
      features : {
          FetchExternalResources : ['script'],
          ProcessExternalResources : ['script']
      },
      done : function (error, window) {
          test(); // I'd like to do something like this.
          console.log(window.document.innerHTML);
      }
  });
  </code></pre>