最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Documenting a private constructor with JSDoc - Stack Overflow

programmeradmin2浏览0评论

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 binations I've tried with JSDoc tags (e.g. @private, @constructs, etc.) can't seem to suppress it from the built docs.

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 binations I've tried with JSDoc tags (e.g. @private, @constructs, etc.) can't seem to suppress it from the built docs.

Share Improve this question asked Dec 11, 2014 at 17:55 Justin MakeigJustin Makeig 2,13715 silver badges29 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

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
}

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/tags-ignore.html

发布评论

评论列表(0)

  1. 暂无评论