2017-07-06 7 views
1

私は人の名前としてキー名を持つプロパティを持つオブジェクトを取り込むJSDocでES6クラスを文書化する必要があります。そのため、キー名はほとんどすべての文字列にすることができます。だから、オブジェクトの構造は、次のようにする必要があります:JSDoc - 一般的なキー名でオブジェクトをドキュメント化する方法

{ 
    "Name of person": { 
     "age": 31, 
     "hobby": "Tennis" 
    }, 
    "Name of another person": { 
     "age": 29, 
     "hobby": "Running" 
    } 
} 

だから、一人一人の名前が鍵となるが、それはまったく何もすることができ、それが事前に定義されていません。

class ExampleClass { 
    /** 
    * Creates an instance of ExampleClass 
    * @param {Object} peopleObj   - Contains information about people. 
    * @param {String} peopleObj.name  - The name of the person. <----- how should this be documented? 
    * @param {Number} peopleObj.name.age - The age of the person. 
    * @param {String} peopleObj.name.hobby - The hobby of the person. 
    * @memberof ExampleClass 
    */ 
    constructor(peopleObj) { 
     // Do stuff 
    } 
} 

私は「peopleObj.name」を置けば、それはキーが「名前」ではなく、あなたが好きな名前でなければならないことを暗示のように私は感じる:私は、ドキュメントにしようとしているものの例。だから私は彼が好きな名前を挿入できることをユーザーに知らせるためにこれを文書化しますか?


EDIT

思って誰のために、これは私は(誰かがこの質問を閉じたので、答えとして、それを追加することはできません)、これを文書化することになった方法です。

/** 
* Information about a single person. 
* @typedef Person 
* @type {object} 
* @property {number} age - The age of the person. 
* @property {string} hobby - The hobby of the person. 
*/ 
class ExampleClass { 
    /** 
    * Creates an instance of ExampleClass. 
    * @param {Object.<string, Person>} peopleObj - Information about people as {@link Person} 
    *            objects where the key is their name. 
    * @memberof ExampleClass 
    */ 
    constructor(peopleObj) { 
     // Do stuff 
    } 
} 
+0

あなたは辞書を文書化する本質的にしているので、私は質問ではなく大会/テキストの問題を命名に関するもの見つけ@Icepickle重複は、上記 – Icepickle

+0

を適用すべきである、ということでした間違った解釈? – Teemu

+0

@Teemu私は読むことができるので、彼はそれを辞書(変数名を持つオブジェクト)に送っているようだから、どのオブジェクトをコンストラクタに渡すべきかを文書化する必要があることを知りたがっています。重複は正しいはずです。しかし、私はOPが彼の考えを与えることができると確信しています:) – Icepickle

答えて

0

おそらくこれは?

class ExampleClass { 
    /** 
    * Creates an instance of ExampleClass 
    * @param {Object} peopleObj    - Contains information about people. 
    * @param {String} peopleObj.{name}  - The name of the person (as a key in peopleObj) 
    * @param {Number} peopleObj.{name}.age - The age of the person. 
    * @param {String} peopleObj.{name}.hobby - The hobby of the person. 
    * @memberof ExampleClass 
    */ 
    constructor(peopleObj) { 
     // Do stuff 
    } 
} 

標準ではありませんが、ポイントを取得します。コメントの本文やパラメータの説明にこれを記述することもできます。

1

あなたの説明は、@type JSDocのドキュメントに記載されています。

は、次のようにオブジェクトを文書化する必要があり

/** 
* @typedef Person 
* @type {Object} 
* @property {number} age - the person's age 
* @property {string} hobby - the person's hobby 
*/ 

/** 
* ExampleClass 
*/ 
class ExampleClass { 

    /** 
    * Creates a dictionary of people 
    * @param {Object.<string, Person>} peopleObj - an object with names as keys and Person objects as values. 
    * @memberof ExampleClass 
    */ 
    constructor(peopleObj) {} 
} 
関連する問題