Javascript 如何为这样一个对象定义JSDoc?
例如,我通过@name有一个对象描述:Javascript 如何为这样一个对象定义JSDoc?,javascript,jsdoc,jsdoc3,Javascript,Jsdoc,Jsdoc3,例如,我通过@name有一个对象描述: /** @name Point @prop {number} x @prop {number} y */ 以及一个对象,其中每个属性都是点: /** * * @type {what?} */ var details = { something: {x:1.1, y: 2.2}, another: {x:1.1, y: 2.2}, theRest: {x:1.1, y: 2.2}, more: {x:1.1, y: 2.2}
/**
@name Point
@prop {number} x
@prop {number} y
*/
以及一个对象,其中每个属性都是点:
/**
*
* @type {what?}
*/
var details = {
something: {x:1.1, y: 2.2},
another: {x:1.1, y: 2.2},
theRest: {x:1.1, y: 2.2},
more: {x:1.1, y: 2.2},
yetAnother: {x:1.1, y: 2.2}
};
应该是什么类型的?是否可以仅通过属性值而不使用键来设置类型?因为我将动态添加/删除属性,但所有值都将始终是点
可以用jsDoc来描述吗?据我所知,在jsDoc中定义对象的键和类型有两种方法 使用
@property
定义的JSDocs:
/**
@typedef PropertiesHash
@type {object}
@property {string} id - an ID.
@property {string} name - your name.
@property {number} age - your age.
/
/** @type {PropertiesHash} /
var props;
其中,当在Google中使用时,特别是与首选的{{key:(type)}
结构:
/**
* A typedef to represent a CSS3 transition property. Duration and delay
* are both in seconds. Timing is CSS3 timing function string, such as
* 'easein', 'linear'.
*
* Alternatively, specifying string in the form of '[property] [duration]
* [timing] [delay]' as specified in CSS3 transition is fine too.
*
* @typedef { {
* property: string,
* duration: number,
* timing: string,
* delay: number
* } | string }
*/
goog.style.transition.Css3Property;
要直接回答您的问题,听起来好像您不知道所有的键,因此您必须使用更简单的定义
/** @type {Object<string, Point>} */
/**@type{Object}*/
或速记
/** @type {Object<Point>} */
/**@type{Object}*/