tags:

views:

47

answers:

2

Is there a way to read a set of JavaScript files, and output a description of where every function/method is defined?

I realize that this is likely impossible in full generality, due to the extreme dynamic nature of the language. What I'm imagining is something which gets the (relatively) straightforward cases. Ideally, I'd want it figure out where, e.g. some method got attached to string or hash or some other fundamental class (and also just let you find all the classes/functions that get defined once in one place).

Does such a tool exist?

A: 

Give Eclipse (with JSDT) or Aptana a try.

The Outline view of a JavaScript file gives great view of functions and object hierarchies.

Granted this will only work for a single js file, and it sounds like your looking for more of a report, so I guess I need to ask what your ultimate goal is.

BozoJoe
I'm working on an existing JS codebase, which pulls in a few libraries (jQuery + parts of MooTools), and then adds on a bunch of methods to core classes (like, e.g. hash). There are many, many file included in every web page. I'd like to pass that set of files to a tool and have it tell me where things are defined, so I can read the code and, e.g., find the definition of a method I see used. Does that make sense?
Dan Milstein
Unfortunately now many libraries are using scopes and namespaces to hide function definitions, this isn't as doable as it once was.
bobince
A: 

I'm not sure if it will output anything without documentation comments, but you could give YUI Doc a try.

Husky