How to Document Self-executing Anonymous Javascript Function using JSDoc?

By | November 2, 2016

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);
Vishal Monpara is a full stack Solution Developer/Architect with 12 years of experience primarily using Microsoft stack. He is currently working in Retail industry and moving 1’s and 0’s from geographically dispersed hard disks to geographically dispersed user’s mind leveraging geographically dispersed team members.

Leave a Reply

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