gpt4 book ai didi

javascript - 当它是包含对象的数组时如何在 JSDoc 中记录变量?

转载 作者:行者123 更新时间:2023-11-29 15:30:13 25 4
gpt4 key购买 nike

我必须遵循以下数据结构:

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 = [];

关于javascript - 当它是包含对象的数组时如何在 JSDoc 中记录变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35651802/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com