title: Retrieve javascript comments in javascript, or, how do I parse js in js?
body: <p>I am looking for a way to access javascript comments from some (other) javascript code.
  I plan on using this to display low level help information for elements on the page that call various js function without duplicating that information in multiple places.</p>
  
  <p>mypage.html:</p>
  
  <pre><code>...
  &lt;script src="foo.js"&gt;&lt;/script&gt;
  ...
  &lt;span onclick="foo(bar);"&gt;clickme&lt;/span&gt;
  &lt;span onclick="showhelpfor('foo');&gt;?&lt;/span&gt;
  ...
  </code></pre>
  
  <p>foo.js:</p>
  
  <pre><code>/**
   * This function does foo.
   * Call it with bar.  Yadda yadda "groo".
   */
  function foo(x)
  {
      ...
  }
  </code></pre>
  
  <p>I figure I can use getElementsByTagName to grab the script tag, then load the file with an AJAX request to get the plain text content of it.  However, then I'd need a way to parse the javascript in a reliable way (i.e. not a bunch of hacked together regexp's) that preserves the characters that simply eval'ing it would throw away.</p>
  
  <p>I was thinking of simply putting the documentation after the function, in a js string, but that's awkward and I have a feeling getting doxygen to pick that up will be difficult.</p>
  
  <pre><code>function foo(x) { ... }
  foo.comment = "\
  This functions does foo.\
  Call it with bar.  Yadda yadda \"groo\".\
  ";
  </code></pre>