如何在JSDoc 3标记中记录对象的属性:@this

Mat*_*att 34 this jsdoc

@param标签允许性质的文件,如

 /**
  * @param {Object} userInfo Information about the user.
  * @param {String} userInfo.name The name of the user.
  * @param {String} userInfo.email The email of the user.
  */
Run Code Online (Sandbox Code Playgroud)

我如何记录@this标签的属性?

 /**
  * @this {Object} 
  * @param {String} this.name The name of the user.
  * @param {String} this.email The email of the user.
  */
Run Code Online (Sandbox Code Playgroud)

我想知道是否有人在该项目上工作.(文档仍在创建......)

laz*_*azd 52

要记录实例成员,请使用@name Class#member:

/**
  Construct a new component

  @class Component
  @classdesc A generic component

  @param {Object} options - Options to initialize the component with
  @param {String} options.name - This component's name, sets {@link Component#name}
  @param {Boolean} options.visible - Whether this component is vislble, sets {@link Component#visible}
*/
function Component(options) {
  /**
    Whether this component is visible or not

    @name Component#visible
    @type Boolean
    @default false
  */
  this.visible = options.visible;

  /**
    This component's name

    @name Component#name
    @type String
    @default "Component"
    @readonly
  */
  Object.defineProperty(this, 'name', {
    value: options.name || 'Component',
    writable: false
  });
}
Run Code Online (Sandbox Code Playgroud)

这会导致文档中的Members部分列出每个成员,其类型,默认值以及它是否为只读.

由jsdoc@3.3.0-alpha3生成的输出如下所示:

JSDoc3输出

也可以看看:


Lar*_*tle 5

使用@property标记来描述对象的属性。

@param 用于定义方法或构造函数的参数。

@this用于定义this引用哪个对象。因此,这是使用JSDOC 3的示例。

/**
* @class Person
* @classdesc A person object that only takes in names.
* @property {String} this.name - The name of the Person.
* @param {String} name - The name that will be supplied to this.name.
* @this Person
*/
var Person = function( name ){
    this.name = name;
};
Run Code Online (Sandbox Code Playgroud)

JSDOC 3:https//github.com/jsdoc3/jsdoc

详细信息:http : //usejsdoc.org/index.html

更多信息:http : //code.google.com/p/jsdoc-toolkit/wiki/TagParam

  • 我相信这实际上记录了`Person`的构造函数的属性,而不是`Person`实例的属性。它还在文档下添加了一个标题为“ This•Person”的项目,该项目无用。 (5认同)