Note that there are some explanatory texts on larger screens.

plurals
  1. PODetermining Source Line and File of function reference - How does Firebug do it?
    primarykey
    data
    text
    <p>Brief introduction:</p> <p>I'm attempting to get at line number of function definition for parsing documentation comments on only public stuff. I've gotten to the point where I can find the name of the function and if I so wanted I could execute the function, but I can't seem to figure out any way to pull out line number information. Note: this is purely for documentation purposes so cross-browser isn't necessary.</p> <p>I know firebug (but not firebug lite so I don't know how possible this is) shows you the line number and script location of a referenced function on mouseover. I looked through the firebug source and got as far as finding they call (<code>domPanel.js:536</code>), but can't seem to find this "addMember" function anywhere in their source:</p> <pre><code>this.addMember(object, "userFunction", userFuncs, name, val, level, 0, context); </code></pre> <p>It may be that this just isn't possible to determine. My fallbacks are using <code>[userfunction].name</code> and <code>[userfunction].toSource()</code> and then attempt to match source to source. But I would like to avoid these if possible since the name could be non-unique and the toSource() gives the source post-processing. Maybe there is a way to tie into the firebug api?</p> <p>Minimal Explanation Code:</p> <p>[Note the goal would be to get this information: <code>window.MyWindowObject.PublicFunction: script.js line 3</code>]</p> <p>script.js</p> <pre><code>(function () { function referencedFunction() { ///&lt;summary&gt;Sample XML Doc Comment&lt;/summary&gt; alert('well hello there!'); } var publicObject = window.MyWindowObject || {}; publicObject.PublicFunction = referencedFunction; window.MyWindowObject = publicObject; }()); </code></pre> <p>index.htm</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;script src="script.js"&gt;&lt;/script&gt; &lt;/html&gt; </code></pre> <p>EDIT: for anyone who finds this on a search later here is some other useful related info that I've found:</p> <p>Stacktrace.js: <a href="https://github.com/eriwen/javascript-stacktrace" rel="noreferrer">https://github.com/eriwen/javascript-stacktrace</a> - Pretty close but not quite what I want since it doesn't seem to get the final function's location. The example on their website is not correct (though the demo "looks" like what I wanted)</p> <p>In chrome (and IE9): <code>[userfunction].toString()</code> preserves comments (does not in firefox), which is what I will probably end up using. I was going to use firefox's <code>[userfunction]</code>.toSource() but this looks like browser-manipulated source of the function. firefox's <code>[userfunction]</code>.toString() appears to preserve code, but strips comments</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload