42

@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.
  */

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

 /**
  * @this {Object} 
  * @param {String} this.name The name of the user.
  * @param {String} this.email The email of the user.
  */

我想知道是否有从事该项目的人知道。(文档仍在创建中...)

4

3 回答 3

65

要记录实例成员,请使用@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 visible, 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
    });
}

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

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

JSDoc3 输出

也可以看看:

于 2014-01-23T19:10:35.053 回答
6

使用@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;
};

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

更多信息:http ://usejsdoc.org/index.html

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

于 2012-05-31T22:07:46.633 回答
2

在类的构造函数中,jsdoc 将自己意识到文档化的属性属于类实例。所以这应该足够了:

/**
 * @classdesc My little class.
 *
 * @class
 * @memberof module:MyModule
 * @param {*} myParam Constructor parameter.
 */
function MyLittleClass(myParam) {
    /**
     * Instance property.
     * @type {string}
     */
    this.myProp = 'foo';
}

如果 jsdoc 不清楚该函数是类构造函数,可以使用@this来定义this指的是什么:

/**
 * @classdesc My little class.
 *
 * @class
 * @memberof module:MyModule
 * @name MyLittleClass
 * @param {*} myParam Constructor parameter.
 */

// Somewhere else, the constructor is defined:
/**
 * @this module:MyModule.MyLittleClass
 */
function(myParam) {
    /**
     * Instance property.
     * @type {string}
     */
    this.myProp = 'foo';
}
于 2016-07-15T13:31:42.800 回答