Search code examples
jsdocjs-amd

Why is JSDoc clubbing doc comments across all JS modules in one file?


I have multiple JS files (AMD modules) in a directory. When I run jsdoc command, it generates an index.html file that has doc comments for all the methods across all the files. Why is it clubbing all methods in one file ?

Am using the following command

jsdoc D:\JSworks\shell\widgets -r -d D:\output

I want index.html to have links to each module, clicking on which it should show the docs for methods of only that particular module. How do I achieve this ?


Solution

  • I don't know how your classes look, but here's an example of how to comment an AMD module in order for JSDoc to properly generate documentation for it:

    /**
     * A Model for users
     * @module  UserModel
     * @exports UserModel
     * @extends AbstractModel
     */
    
    define(["model/AbstractModel"], 
    function(AbstractModel ) {
    
        return UserModel = new Class(
            /** @lends module:UserModel */
            {
                Extends : AbstractModel,
    
                /**
                 * Constructor
                 * @memberOf module:UserModel#
                 */
    
                initialize: function() {
                    this.parent();
                },
    
                /**
                 * Sets the model value
                 * @memberOf module:UserModel#
                 * @param {object} value Value to set the model to           
                 */
    
                 setValue: function(value){
                    // do something
                 }
    
                /**
                 * Responsible for returning user metadata
                 * @memberOf module:UserModel#
                 * @param {object} user User
                 */
    
                getMetaData: function(user) {
                    // do something
                }
            }
        );
    });
    

    This class will generate the following documentation: enter image description here

    The complete list of tags to use in JSDOC is available at http://usejsdoc.org/index.html#JSDoc3_Tag_Dictionary