2012-05-07 6 views
24

@paramタグ例えば、プロパティのドキュメントを許可しますJSDocの3タグでオブジェクトのプロパティを文書化する方法:@this

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

私は、プロジェクトに携わっている人が誰か知っていますか? (ドキュメントがまだ作成されている...)

答えて

40

@name Class#memberを使用して、インスタンスメンバーを文書化する:

は、だからここ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を使用した例です

/** 
    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 
    }); 
} 

これは、各メンバー、そのタイプ、デフォルト値を示していますドキュメントのメンバーセクションになり、それは読み取り専用ですか。

[email protected]によって生成される出力は次のようになります。また、

JSDoc3 output

参照:

+0

これは '' var Component = function(){} ''パラダイムでどのように動作しますか? –

+0

これは私のためには機能しません。何も得られません。 –

5

オブジェクトの属性を記述するために@propertyタグを使用してください。

@paramはメソッドまたはコンストラクタのパラメータを定義するために使用されます。

@thisthisが参照するオブジェクトを定義するために使用されます。 https://github.com/jsdoc3/jsdoc

詳細情報::http://usejsdoc.org/index.html

さらに詳しい情報:http://code.google.com/p/jsdoc-toolkit/wiki/TagParam

+5

私はこの実際に文書を信じます'Person'のインスタンスではなく、' Person'のコンストラクタのプロパティです。また、ドキュメンテーションの下に "This•Person"という項目が追加されていますが、これは有用ではありません。 – lazd

+0

'' @this Person''タグは単純に省略することができます。これは '' @ class''ブロック内で冗長です。 – Ignitor

1

クラスのコンストラクタ内で、jsdocは、ドキュメント化されたプロパティがクラスintancesに属していることを認識します。だから、これは十分なはずです:

/** 
* @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'; 
} 
関連する問題