0

I have a special JS revealing module pattern like in the example below and I am trying to document using JSDoc 3.

The situation is similar to this and this, but my constructor has arguments and there isn't a prototype root variable.

If I put @class in My Module along with @param for config, which seems to be the most correct alternative, it works fine (description, author and dependencies are properly written) but I have to put @instance/@memberof/@name in every prototype member, which is pretty annoying.

If I put @constructor in Constructor every member is properly recognized but the constructor is documented twice.

Then if I remove @class from My Module, the description, @author and @requires never appears. Putting @lends in My Module and @constructs in Constructor produces the same effect.

Changing the code is not a option, it is a widely used pattern in my company.

How to proceed?

var Root = window.Root || {};

/**
 * My module
 *
 * @author ...
 * @requires DependencyOne
 * @requires DependencyTwo
 */
Root.MyModule = (function(DepOne, DepTwo) {
    var _private = {/*...*/};

    /**
     * Constructor
     *
     * @param {Object} config
     * @param {String} config.prop
     */
    function MyModule(config) {
        this.config = config;
    }

    /**
     * My attribute
     *
     * @type {String}
     */
    MyModule.prototype.myAttribute = null;

    /**
     * My function
     *
     * @param {String} param
     * My parameter
     */
    MyModule.prototype.myFunction = function(param) {/*...*/}

    return MyModule;
})(DependencyOne, DependencyTwo);

Solution: After some tests I figured out how to proceed, using @class/@constructor and @memberof:

var Root = window.Root || {};

Root.MyModule = (function(DepOne, DepTwo) {
    var _private = {/*...*/};

    /**
     * Constructor.
     *
     * @constructor
     * @memberof Root
     *
     * @requires DependencyOne
     * @requires DependencyTwo
     *
     * @param {Object} config My config
     * @param {String} config.prop Property
     */
    function MyModule(config) {
        this.config = config;
    }

    /**
     * My attribute
     *
     * @type {String}
     */
    MyModule.prototype.myAttribute = null;

    /**
     * My function
     *
     * @param {String} param
     * My parameter
     */
    MyModule.prototype.myFunction = function(param) {/*...*/}

    return MyModule;
})(DependencyOne, DependencyTwo);
Community
  • 1
  • 1
fsmaia
  • 1
  • 2
  • Did you ever figure this out? I'm wondering the same thing. – Rob G Jun 14 '16 at 19:39
  • 1
    Yes, I edited the question with the solution: the key was to face it like a class, not module. `@memberof` did the trick of grouping the classes by namespace. – fsmaia Jun 15 '16 at 21:48
  • Thanks! So did you have @namespace before your Root.MyModule? – Rob G Jun 16 '16 at 19:49
  • 1
    No, actually there was no need. By using `@memberof` the classes were displayed automatically under root namespace. In our scenario root wasn't actually a class, but a simple object. When I get back to documentation process I'll try to improve root as a class to figure out how it should be documented as well. – fsmaia Jun 20 '16 at 14:16

0 Answers0