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参照するかを定義するために使用されます。したがって、JSDOC3を使用した例を次に示します。

/**
* @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 に答える