Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsdoc self executing anonymous function

Tags:

module

jsdoc

How can i document a module like this with jsdoc? I tried many version, but can't get it work. Funciton test doesn't appear in the documentation.

/**
 * Description of module, defines module for whole file
 *    
 * @module constructors
 * @exports app
 */


var app = (function() {
    /**
     * Description of function test
     */
    function test() {
        return '';
    }

    return {
        test: test
    }
}());
like image 828
user3414859 Avatar asked Dec 28 '25 10:12

user3414859


2 Answers

As of version 3.2.2, jsdoc is easily tripped by modules, the solution is to use module: with the module name to specify where the entity you are documenting resides:

/**
 * Description of module, defines module for whole file
 *
 * @module constructors
 */

var app = (/** @lends module:constructors */ function() {
    /**
     * Description of function test
     */
    function test() {
        return '';
    }

    return {
        test: test
    }
}());
like image 145
Louis Avatar answered Dec 30 '25 23:12

Louis


For me, using JSDoc 3.4.0 helped this solution:

/**
 * @module array-cop
 */

/**
* @function
* @name Anonymous self-invoked function
* @description Call main module
* @param {Object} this Window for the browser
*/

(function(_) {

    var array_ = {
      /**
      * @function
      * @name check
      * @description Method for checking type of the source data.
      * @param {Array} arr  Source data.
      * @returns {Boolean} Returns true if Array.isArray, otherwise throw error.
      * @throws Will throw an error "Not an array" if the argument isn't array.
      */
        check: function(arr) {
            return Array.isArray(arr) || (function() {
                throw new Error("Not an array!");
            }());
        },

// Some code stuff

    /**
     * npm / <script> compatibility
     */

    if (typeof module !== "undefined" && module.exports) {
        module.exports = array_;
    } else {
        _.array_ = array_;
    }
}(this));

and also I created gulp task for generate JSDoc documentation:

var gulp = require('gulp'),
    child_exec = require('child_process').exec;

// Task for generationg JSDoc
gulp.task('docs', function(done) {

    var settings = {
      docGenerator: "./node_modules/jsdoc/jsdoc.js",
      srcFile: "./src/array-cop.js",
      jsDocConfPath: "./jsdoc.json",
      docsOutputPath: "./docs"
    }

    child_exec('node '
                + settings.docGenerator
                + ' ' + settings.srcFile
                + ' -c ' + settings.jsDocConfPath
                + ' -d ' + settings.docsOutputPath, undefined, done);
});

after running gulp docs documentation will be placed to the ./docs folder

like image 27
Nikolay Ignatyev Avatar answered Dec 30 '25 22:12

Nikolay Ignatyev