2016-02-26 284 views
3

我有下面的数据结构:当JSDoc是一个包含对象的数组时,文档如何变量?

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

回答

1

{[].<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 = []; 
+0

喔,不知何故,我错过了那个页面。谢谢你的回答,这对我来说似乎有点复杂。 – NoNameProvided

相关问题