Documenting a javascript class with prototypes in a namespace using jsdoc-toolkit

dave picture dave · Apr 11, 2011 · Viewed 9.8k times · Source

I'm trying very hard to document code in the format below using jsdoc-toolkit. It looks to me like the tags I've used should produce the desired result but it doesn't. Instead it warns that Class is undocumented (because it is only defined inside the closure) and doesn't include Class in list of members of namespace.

I'm would like to document this without resorting to using the @name tag if possible. Can anyone help?

/**
 * @namespace The original namespace
 */
var namespace = function () {
    // private
    /**
     * @private
     */
    function _privateMethod () {

    };

    /**
     * This is the detail about the constructor
     * @class This is the detail about the class
     * @param {Object} argone The first argument
     * @param {Object} argtwo The second argument
     */
    var Class = function (argone, argtwo) {
        /**
         * A public member variable
         */
        this.member = "a member";
    };

    /**
     * A public method
     * @param {Object} argone The first argument
     */
    Class.prototype.publicMethod = function (argone) {

    };

    return /** @lends namespace */ {
        Class: Class
    }
}();

Answer

ericponto picture ericponto · Jan 8, 2013

I tried a bunch of different things and this was the best I could come up with.

The first part...documenting the publicMethod on Class. First make Class a memberOf namespace and then use @lends on the Class.prototype. Example:

/**
 * @namespace The original namespace
 */
var namespace = function () {
    // private
    /**
     * @private
     */
    function _privateMethod () {

    };

    /**
     * This is the detail about the constructor
     * @class This is the detail about the class
     * @memberOf namespace
     * @param {Object} argone The first argument
     * @param {Object} argtwo The second argument
     */
    var Class = function (argone, argtwo) {
        /**
         * A public member variable
         */
        this.member = "a member";
    };

    Class.prototype = 
    /** @lends namespace.Class */ 
    {
        /** a public method
          * @param {Object} argone The first argument
        */
        publicMethod: function (argone) {

        }
    };

    return {
        Class: Class
    }
}();

Now, the second part...getting Class to show up as on the namespace. I'm not sure how to do that...sorry! It will show up as namespace.Class in the class index.