Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documenting a private constructor with JSDoc

I've got a class where individual methods may be called statically but will return a new instance of class in order to chain, for example:

var builder = ns
  .setState('a', 'A')
  .setState('b', 'B');

Where Builder is defined as such:

/** 
 * @module Builder 
 */

/**
 * @class Builder 
 */

/**
 * @private
 */
function Builder() {
  this.state = {
    query: {}
  };
}
Builder.prototype = {
  /**
   * @param {string} k - The key
   * @param {object} v - The value
   * @return {Builder}
   */
  setState: function(k, v) {
    var that = (this instanceof Builder) ? this : new Builder();
    that[k] = v;
    return that;
  }
  // Other properties and methods…
}

The Builder constructor is never supposed to be called explicitly by user code and thus I'd like it not to show up in the docs. However, all of the combinations I've tried with JSDoc tags (e.g. @private, @constructs, etc.) can't seem to suppress it from the built docs.

like image 629
Justin Makeig Avatar asked Dec 11 '14 17:12

Justin Makeig


Video Answer


2 Answers

From version 3.5.0 of jsDoc, you can use tag @hideconstructor on the class, telling jsDoc not to include the constructor into documentation.

/**
 * @class Builder
 *
 * @hideconstructor
 */
function Builder() {
    // implementation
}
like image 180
vitaly-t Avatar answered Oct 05 '22 09:10

vitaly-t


You should be able to use the @ignore directive to achieve this. From the docs:

The @ignore tag indicates that a symbol in your code should never appear in the documentation. This tag takes precedence over all others.

http://usejsdoc.org/tags-ignore.html

like image 20
Jim Fitzpatrick Avatar answered Oct 05 '22 08:10

Jim Fitzpatrick