0

I have an object that contains multiple methods and is a member of a class. How would I document this with JSDoc?

Here's my attempt. With this SomeClass#helperFunctions is documented, but both of it's methods are omitted.

/**
 * @class SomeClass
 * @param name
 */
var SomeClass = function(name) {};

/**
 * @member SomeClass#helperFunctions
 */
SomeClass.prototype.helperFunctions = {
  /**
   * @method SomeClass#helperFunctions.doSomething
   * @param {Array} arr
   */
  doSomething: function(arr) {}
};

/**
 * @method SomeClass#helperFunctions.doSomethingElse
 * @param {Array} arr
 */
SomeClass.protype.helperFunctions.doSomethingElse = function(arr) {};
Hal Carleton
  • 4,054
  • 6
  • 31
  • 55

1 Answers1

0

This is the best I could come up with.

I document methods of SomeClass#helperFunctions as globals then include them as properties of SomeClass#helperFunctions using links.

/**
 * @class SomeClass
 * @param {String} name
 */
var SomeClass = function(name) {};

/**
 * @member SomeClass#helperFunctions
 * @property {Function} doSomething [_doSomething]{@link _doSomething}
 * @property {Function} doSomethingElse [_doSomethingElse]{@link _doSomethingElse}
 */
SomeClass.prototype.helperFunctions = {
  doSomething: _doSomething,
  doSomethingElse: _doSomethingElse
};

/**
 * @function _doSomething
 * @param {Array} arr
 */
_doSomething = function(arr) {};

/**
 * @function _doSomethingElse
 * @param {Array} arr
 */
_doSomethingElse = function(arr) {};

In my actual application SomeClass was also a module so it was written as:

/**
 * @module path/to/SomeClass
 */

/**
 * @class module:path/to/SomeClass
 */
var SomeClass = module.exports = function() {};

Then the links were written as {@link module:path/to/SomeClass~_doSomething} so it would link to it's spot on the module page instead of looking for them in Globals.

Hal Carleton
  • 4,054
  • 6
  • 31
  • 55