开发者

JSDoc Toolkit - How to specify @param and @property on same line

开发者 https://www.devze.com 2023-03-15 13:47 出处:网络
Is there a way to avoid having to type two seperate lines for @property and @param if, as in the example, on the constructor the parameters and properties are identically named.

Is there a way to avoid having to type two seperate lines for @property and @param if, as in the example, on the constructor the parameters and properties are identically named.

/**
 * Class for representing a point in 2D space.
 * @property {number} x The x coordinate of this point.
 * @property {number} y The y coordin开发者_开发问答ate of this point.
 * @constructor
 * @param {number} x The x coordinate of this point.
 * @param {number} y The y coordinate of this point.
 * @return {Point} A new Point
 */
Point = function (x, y)
{
    this.x = x;
    this.y = y;
}


You do not. It is impossible, because the arguments of the function and properties of an object - these are different variables, they can not be both function parameters and object properties. Moreover, such documentation would only confuse the developer, but does not help to understand the API.

I would advise you not to use the @properties in this piece of documentation, but use @type:

/**
 * Class for representing a point in 2D space.
 * @constructor
 * @param {number} x The x coordinate of this point.
 * @param {number} y The y coordinate of this point.
 * @return {Point} A new Point
 */
Point = function (x, y)
{
    /**
     * The x coordinate.
     * @type number
     */
    this.x = x;

    /**
     * The y coordinate.
     * @type number
     */
    this.y = y;
}

But in fact such detailed documentation is useless. What are we talking in code Point.x = x is clear to any schoolchild.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号