当它是包含对象的数组时如何在 JSDoc 中记录变量?
How document variable in JSDoc when it is an array containing objects?
我必须遵循以下数据结构:
this.subscribers = [
{
callback: () => {console.log( 'my callback'); },
interval: 5,
remaining: 3
},
{
callback: () => {console.log( 'my callback 2'); },
interval: 20,
remaining: 1
}
];
我是这样写 JSDoc 的:
/**
* This variable store the array of callbacks to call repeatedly with the specified interval.
* @property {function} callback - The callback function the SchedulerService call.
* @property {number} interval - The number of minutes between the runs.
* @property {number} remaining - The remaining minutes until the next call.
* @type {Array}
*/
this.subscribers = [];
但是对于这个 jsdoc,subscriptions
变量应该如下所示:
this.subscribers = [];
this.subscribers.callback = () => {};
this.subscribers.interval = 10;
this.subscribers.remaining = 2;
这个 属性 的正确 JSDoc 评论是什么样的?
注意:我们在这里谈论的是 @property
而不是 @param
。
{[].<TypeOfObject>}
或
{Array.<TypeOfObject>}
我觉得有点尴尬,但您可以在 docs 行中看到一个示例:
数组和对象(类型应用和记录类型)
在您的情况下,您首先要定义 Subscriber
类型:
/**
* @typedef {Object} Subscriber
* @property {function} callback - The callback function the SchedulerService call.
* @property {number} interval - The number of minutes between the runs.
* @property {number} remaining - The remaining minutes until the next call.
*/
然后您将在构造函数中引用类型(无论它是什么),如下所示:
/**
* This variable store the array of callbacks to call repeatedly with the specified interval.
* @type {Array.<Subscriber>}
*/
this.subscribers = [];
我必须遵循以下数据结构:
this.subscribers = [
{
callback: () => {console.log( 'my callback'); },
interval: 5,
remaining: 3
},
{
callback: () => {console.log( 'my callback 2'); },
interval: 20,
remaining: 1
}
];
我是这样写 JSDoc 的:
/**
* This variable store the array of callbacks to call repeatedly with the specified interval.
* @property {function} callback - The callback function the SchedulerService call.
* @property {number} interval - The number of minutes between the runs.
* @property {number} remaining - The remaining minutes until the next call.
* @type {Array}
*/
this.subscribers = [];
但是对于这个 jsdoc,subscriptions
变量应该如下所示:
this.subscribers = [];
this.subscribers.callback = () => {};
this.subscribers.interval = 10;
this.subscribers.remaining = 2;
这个 属性 的正确 JSDoc 评论是什么样的?
注意:我们在这里谈论的是 @property
而不是 @param
。
{[].<TypeOfObject>}
或
{Array.<TypeOfObject>}
我觉得有点尴尬,但您可以在 docs 行中看到一个示例:
数组和对象(类型应用和记录类型)
在您的情况下,您首先要定义 Subscriber
类型:
/**
* @typedef {Object} Subscriber
* @property {function} callback - The callback function the SchedulerService call.
* @property {number} interval - The number of minutes between the runs.
* @property {number} remaining - The remaining minutes until the next call.
*/
然后您将在构造函数中引用类型(无论它是什么),如下所示:
/**
* This variable store the array of callbacks to call repeatedly with the specified interval.
* @type {Array.<Subscriber>}
*/
this.subscribers = [];