<分区>
我需要用 JSDoc 记录一个 ES6 类,该类接受一个对象,该对象具有以键名作为人名的属性,因此键名几乎可以是任何字符串,没有任何预定义。所以对象的结构应该是这样的:
{
"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”就意味着键应该是“name”而不是任何你喜欢的名字。那么我如何通过让用户知道他可以在那里插入他喜欢的任何名称来记录这一点?
编辑
对于任何想知道的人,这就是我最终记录的方式(由于有人关闭了这个问题,无法将其添加为答案)。
/**
* 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
}
}