JSDoc: How to document your JavaScript

Monday, March 2nd, 2009 | Business, Tutorials | by

JSDoc is meant to do for Javascript, what Javadoc does for Java.

It does.  

You can download and install JSDoc easily:

  1. Download JSDoc
  2. Expand the tgz.gz file (I use Winrar)
  3. Optional – I copy the jsdoc folder to my C: drive to make things easier
  4. Reminder – you need a perl runtime installed.  ActivePerl is recommended
  5. Open up a command prompt 
  6. Change to your JSDoc folder (mine is c:\JSDoc-1.10.2\)
  7. 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);

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:

Related Posts

Tags: , , , , , ,

No comments yet.

Leave a comment


Please share, it makes me happy:

Subscribe to Email Alerts

Follow Me

Follow seangw on twitter



prestashop theme

virtuemart template