Search code examples
javascriptjsdoc

JSDoc and JavaScript singleton documentation


I have a JavaScript singleton defined as:

/**
 * A description here
 * @class
 */
com.mydomain.ClassName = (function(){

/**
 * @constructor
 * @lends com.mydomain.ClassName
 */ 
var ClassName = function(){};

/**
 * method description
 * @public
 * @lends com.mydomain.ClassName
*/
ClassName.prototype.method1 = function(){};

return new ClassName();

})();

No warnings are printed in verbose mode (-v), but the documentation reports only "com.mydomain.ClassName()" with "A description here" as description... how can I generate documentation for ClassName's methods too?


Solution

  • I solved! :)

      /**
     * A description here
     * @class
     */
    com.mydomain.ClassName = (function(){
    
    /**
     * @constructor
     * @name com.mydomain.ClassName
     */ 
    var ClassName = function(){};
    
    /**
     * method description
     * @public
     * @name com.mydomain.ClassName.method1
    */
    ClassName.prototype.method1 = function(){};
    
    return new ClassName();
    
    })();
    

    I just replaced @lends with @name!

    UPDATE: the right approach in order to have the full documentation is the following:

    /**
     * A description here
     * @class
     */
    com.mydomain.ClassName = (function(){
    
    var ClassName = function(){};
    
    /**
     * method description
     * @memberOf com.mydomain.ClassName
    */
    ClassName.prototype.method1 = function(){};
    
    return new ClassName();
    
    })();