JSDoc:返回对象结构

我怎么能告诉JSDoc有关返回的对象的结构。 我find了@return {{field1: type, field2: type, ...}} description语法,并试过了:

 /** * Returns a coordinate from a given mouse or touch event * @param {TouchEvent|MouseEvent|jQuery.Event} e * A valid mouse or touch event or a jQuery event wrapping such an * event. * @param {string} [type="page"] * A string representing the type of location that should be * returned. Can be either "page", "client" or "screen". * @return {{x: Number, y: Number}} * The location of the event */ var getEventLocation = function(e, type) { ... return {x: xLocation, y: yLocation}; } 

虽然这parsing成功,结果文档简单地说:

 Returns: The location of an event Type: Object 

我正在开发一个API,需要人们知道他们将返回的对象。 这是可能的JSDoc? 我正在使用JSDoc3.3.0-beta1。

分开定义:

 /** * @typedef {Object} Point * @property {number} x The X Coordinate * @property {number} y The Y Coordinate */ 

并使用:

 /** * Returns a coordinate from a given mouse or touch event * @param {TouchEvent|MouseEvent|jQuery.Event} e * A valid mouse or touch event or a jQuery event wrapping such an * event. * @param {string} [type="page"] * A string representing the type of location that should be * returned. Can be either "page", "client" or "screen". * @return {Point} * The location of the event */ var getEventLocation = function(e, type) { ... return {x: xLocation, y: yLocation}; } 

一个干净的解决scheme是写一个类,并返回。

 /** * @class Point * @type {Object} * @property {number} x The X-coordinate. * @property {number} y The Y-coordinate. */ function Point(x, y) { return { x: x, y: y }; } /** * @returns {Point} The location of the event. */ var getEventLocation = function(e, type) { ... return new Point(x, y); };