Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 438
daveoncode Avatar asked Sep 07 '12 10:09

daveoncode


People also ask

What the purpose of JSDoc is?

JSDoc's purpose is to document the API of your JavaScript application or library. It is assumed that you will want to document things like modules, namespaces, classes, methods, method parameters, and so on. JSDoc comments should generally be placed immediately before the code being documented.

What are JSDoc annotations?

JSDoc is a markup language used to annotate JavaScript source code files. Using comments containing JSDoc, programmers can add documentation describing the application programming interface of the code they're creating.

Is JSDoc useful?

Conclusion. JSDoc makes coding in JavaScript easier, helping us to code quickly while avoiding obvious errors, just by adding some lines of optional comments in our code.

Does JSDoc work with TypeScript?

TypeScript has very rich JSDoc support, for a lot of cases you can even skip making your files . ts and just use JSDoc annotations to create a rich development environment. A JSDoc comment is a multi-line comment which starts with two stars instead of one.


1 Answers

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();

})();
like image 72
daveoncode Avatar answered Oct 14 '22 04:10

daveoncode