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 coordinate 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With