JSDoc: How to document your JavaScript
JSDoc is meant to do for Javascript, what Javadoc does for Java.
It does. Â
You can download and install JSDoc easily:
- Download JSDoc
- Expand the tgz.gz file (I use Winrar)
- Optional – I copy the jsdoc folder to my C: drive to make things easier
- Reminder – you need a perl runtime installed. Â ActivePerl is recommended
- Open up a command promptÂ
- Change to your JSDoc folder (mine is c:\JSDoc-1.10.2\)
- Run it: “perl jsdoc.pl test.js” (to test it against the built in JS file)
Usage of JSDoc is as simple as Javadoc was. Â An example of usage taken from the official JSDoc page is below:
/**
* 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;
}
/**
* Circle is a subclass of Shape
*/
function Circle(radius){
this.radius = radius;
}
/**
* A very rough value for pi
*/
Circle.PI = 3.14;
/**
* Get the radius of this circle
* @returns The radius of this circle
*/
function Circle_getRadius(){
return this.radius;
}
// Circle is a subclass of Shape
Circle.prototype = new Shape(null);
Â
You can use the reference on the official site to learn about more of the “@” attributes you can use for JSDoc. Â
The example code is here:
- test.js – original example javascript file
- JSDoc generated documentation for the test.js file.
Related Posts
No comments yet.
Leave a comment
Tags
2.2
3g
Actionscript
Adobe
AdSense
AJAX
Analytics
Android
Apple
AS3
AT&T
Blog
Chrome
CSS
engadget
Facebook
Firefox
firmware
Flash
Flex
G1
Google
HTML
HTML 5
ie6
IE8
iPad
iPhone
iTunes
Javascript
jQuery
Microsoft
Papervision
Photoshop
PHP
Safari
SEO
T-Mobile
Tethering
Tutorial
tweet
Twitter
Windows 7
WordPress
Youtube
Follow Me
Email Subscription
Recent Posts
Top Commentators
- No commentators.
Archives
Blogroll
- 456 Berea St
- ActionScript 3 Design Patterns
- adactio – home of Jeremy Keith
- ajaxian
- Boxes and Arrows
- Chris Brogan
- CSS Globe
- InsideRIA
- Jarrod Michael Studios
- Mad Vertices
- NETTUTS
- Roomware Blog
- Signal vs. Noise
- Six Revisions
- Snook
- Style Grind
- Tiago’s Weblog
- Viget Extend
- Vitamin
- Whats the latest
- Why Banks Fail
- Woork
- zupko.info















