Justin Makeig
Justin Makeig

Reputation: 2137

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.

Upvotes: 10

Views: 3081

Answers (2)

vitaly-t
vitaly-t

Reputation: 25930

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
}

Upvotes: 2

Jim Fitzpatrick
Jim Fitzpatrick

Reputation: 41

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

Upvotes: 2

Related Questions