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:
[sourcecode language='jscript']/**
* 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);
[/sourcecode]
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
Featured Posts
- HTML Fadein Fadeout: Basic Javascript/AJAX Tutorial using jQuery's fadeTo
- Basic AJAX Tutorial: Smooth Scrolling Text Marquee with a jQuery plugin
- Basic AJAX Tutorial: jQuery toggle and slide
- Hosting: How to pick a WordPress Host
- Basic jQuery Tutorial: Modify CSS classes and attributes, Hover and Toggle example
Follow Me
Email Subscription
Recent Posts
Top Commentators
- No commentators.
Archives
Tags
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
- Portsmouth Community Calendar
- 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
