Is there a standard/tool for documenting JavasSript? I'm thinking of something similar to Javadoc.
No, not widely accepted, but ScriptDoc approach will seem familiar to you if you know Java documentation techniques using the JavaDoc tool, but it has not fully been accepted yet to industry.
Duplicate: What options are available for documenting your Javascript code?
The 800-pound gorilla of Javascript documentation is the JSDoc Toolkit. Check it out here. Most of the documentation is done with Javadoc-like tags and a /**
comment prefix.
Example:
var MyClass = Class.create(
/** @lends MyClass# */ // @lends is how you document anonymous classes.
{
/**
* Description of constructor.
* @class Description of class. // @class annotation goes anywhere and
* // describes the whole class.
* @constructs // This is a constructor.
*/
initialize: function(arg0, arg1) {
//...
},
/** A method. */
myFunc: function() {},
/** An instance field. */
myVar: 123
}
);
Object.extend(MyClass,
/** @lends MyClass */
{
/** A class method. */
classFunc: function() {}
}
);
You can also do NaturalDocs...
Personally, I'm a huge fan of Doxygen. While Javascript isn't one of the officially supported languages, there is a helper script that's supposed to make it work. (I haven't tried Doxygen with Javacript myself, but I did get it working on several hundred thousand lines of Delphi / Pascal code, and JS must be easier.)
There is JSDoc and the Ruby powered Pdoc. There's not really an accepted "standard" but JSDoc probably comes the closest.
You can also use the documentor created for ExtJS: http://code.google.com/p/ext-doc/.
Its amazing, with support for custom tags and fully templated output. It comes with a nice XSL sheet for transforming the output into something useful (the sample obviously converts to the ExtJS style of documentation).
I've used it in my projects with great success.
Check out the thread on it here: http://extjs.com/forum/showthread.php?t=55214