Knowledge.ToString()

How to Document Self-Executing Anonymous Javascript Function Using JSDoc?

I have a class defined in self-executing anonymous Javascript function for which I want to generate the documentation using JSDoc 3.4.2 but I had hard time finding the solution. Solutions searched on the internet did not yield the fruitful result and I had to try various combination of tags in order to get it working. Depending on your style, you may define the class as function or use the prototype. Here are the working examples for both the styles. Position of the @name, @class and @lends tags drives the correct documentation.

Class defined as function

/**
* @name PramukhIME
* @class This class description is required along with @name, @class and @lends in order to generate all the needed information correctly
*/
(function(win) {
    /** @lends PramukhIME
    * @class
    */
 
    function PramukhIME() {
        /**
        * @description Sets language
        */
        this.setLanguage = function() {
            // code to set language
        };
    }
     
})(window);

Class defined using prototype

/**
* @name PramukhIME
* @class This class description is required along with @name, @class and @lends in order to generate all the needed information correctly
*/
(function(win) {
    /** @lends PramukhIME
    * @class
    */
 
    var pramukhime = function() {};
    /**
    * @description Sets language
    */
    pramukhime.prototype.setLanguage = function() {
        // code to set language
    };
     
 
})(window);

Share

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *