autodoc
is teh dope; https://www.npmjs.org/package/autodoc | https://github.com/dtao/autodoc
Autodoc lets you write tests in comments just above your JavaScript functions, then run those tests from the command line and auto-generate documentation with the same tests embedded and executing right in the browser.
Think literate programming, look at http://danieltao.com/lazy.js/docs/ for a nice example. Those green checkmarks are the tests.
✓ Lazy([1, 2, 4]) // instanceof Lazy.ArrayLikeSequence
✓ Lazy({ foo: "bar" }) // instanceof Lazy.ObjectLikeSequence
✓ Lazy("hello, world!") // instanceof Lazy.StringLikeSequence
✓ Lazy() // sequence: []
✓ Lazy(null) // sequence: []
This is what the source looks like github.com/../lazy.js#L86
/**
* Wraps an object and returns a {@link Sequence}. For `null` or `undefined`,
* simply returns an empty sequence (see {@link Lazy.strict} for a stricter
* implementation).
*
* - For **arrays**, Lazy will create a sequence comprising the elements in
* the array (an {@link ArrayLikeSequence}).
* - For **objects**, Lazy will create a sequence of key/value pairs
* (an {@link ObjectLikeSequence}).
* - For **strings**, Lazy will create a sequence of characters (a
* {@link StringLikeSequence}).
*
* @public
* @param {Array|Object|string} source An array, object, or string to wrap.
* @returns {Sequence} The wrapped lazy object.
*
*
* @examples
* Lazy([1, 2, 4]) // instanceof Lazy.ArrayLikeSequence
* Lazy({ foo: "bar" }) // instanceof Lazy.ObjectLikeSequence
* Lazy("hello, world!") // instanceof Lazy.StringLikeSequence
* Lazy() // sequence: []
* Lazy(null) // sequence: []
*/
It extends JSDoc https://developers.google.com/closure/compiler/docs/js-for-compiler, so in addition you can have Google's closure compiler verifying and optimising lot of things for you.