Generate JavaDoc for JavaScript
Wednesday, July 9th, 2008There are couple of options if you want to generate a JavaDoc like documentation for your JavaScript. Generally, most of the time, the JavaScript you write will be collection of simple methods. But, if you do not know, you can create ‘class’ like structures & instantiate them as Objects. That’s one powerful Object Oriented feature of Javascript that many don’t know.
Okay, now coming to point- a documentation of your Javascript, be it functions or full fledged classes, comes in handy & can be major USP for letting developers use your JavaScripts.
One such tool, again from Open source community is “JsDoc”. You can locate it @ http://jsdoc.sourceforge.net/
JsDoc is a Perl script (you will need to install Perl on your comp to run it). Here’s how to download & install “Active Perl”- the most used Perl version for Windows.
JsDoc is not something like Magic trick to automatically add documentation. Like normal Java classes comments or any other language, it requires you properly document your code with appropriate Java like tags such @author, @class, @parameters. Using these tags will help JsDocs to generate JavaDocs for your JavaScript file.
Example, how you need to comment your JavaScript code:
/** * Shape is an abstract base class. It is defined simply * to have something to inherit from for geometric * subclasses * @constructor */ function Shape(color){ this.color = color; } // Bind the Shape_getColor method to the Shape class Shape.prototype.getColor = Shape_getColor; /** * Get the name of the color for this shape * @returns A color string for this shape */ function Shape_getColor(){ return this.color; }
To ease your JavaScript coding, you can try some JavaScript editors or search more.