The @param
tag allow the documentation of properties, e.g.
/**
* @param {Object} userInfo Information about the user.
* @param {String} userInfo.name The name of the user.
* @param {String} userInfo.email The email of the user.
*/
How would I document the properties of the @this tag?
/**
* @this {Object}
* @param {String} this.name The name of the user.
* @param {String} this.email The email of the user.
*/
I'm wondering if anyone working on the project knows. (The docs are still being created...)
The @param tag provides the name, type, and description of a function parameter. The @param tag requires you to specify the name of the parameter you are documenting.
JSDoc comments should generally be placed immediately before the code being documented. Each comment must start with a /** sequence in order to be recognized by the JSDoc parser. Comments beginning with /* , /*** , or more than 3 stars will be ignored.
The @typedef tag is useful for documenting custom types, particularly if you wish to refer to them repeatedly. These types can then be used within other tags expecting a type, such as @type or @param. Use the @callback tag to document the type of callback functions.
JSDoc is an open source API documentation generator for Javascript. It allows developers to document their code through comments.
To document instance members, use @name Class#member
:
/** * Construct a new component * * @class Component * @classdesc A generic component * * @param {Object} options - Options to initialize the component with * @param {String} options.name - This component's name, sets {@link Component#name} * @param {Boolean} options.visible - Whether this component is visible, sets {@link Component#visible} */ function Component(options) { /** * Whether this component is visible or not * * @name Component#visible * @type Boolean * @default false */ this.visible = options.visible; /** * This component's name * * @name Component#name * @type String * @default "Component" * @readonly */ Object.defineProperty(this, 'name', { value: options.name || 'Component', writable: false }); }
This results in a Members section in the documentation that lists each member, its type, default value, and whether it's read only.
The output as generated by [email protected] looks like this:
See also:
@instance
tag@readonly
tag@type
tagUse the @property
tag to describe the attribute of an object.
@param
is used to define the parameters of a method or constructor.
@this
is used to define which object this
refers to. So here's an example using JSDOC 3.
/** * @class Person * @classdesc A person object that only takes in names. * @property {String} this.name - The name of the Person. * @param {String} name - The name that will be supplied to this.name. * @this Person */ var Person = function( name ){ this.name = name; };
JSDOC 3: https://github.com/jsdoc3/jsdoc
More information: http://usejsdoc.org/index.html
More info: http://code.google.com/p/jsdoc-toolkit/wiki/TagParam
Within the constructor of a class, jsdoc will realize by itself that the documented properties belong to class intances. So this should be enough:
/**
* @classdesc My little class.
*
* @class
* @memberof module:MyModule
* @param {*} myParam Constructor parameter.
*/
function MyLittleClass(myParam) {
/**
* Instance property.
* @type {string}
*/
this.myProp = 'foo';
}
If it is not clear for jsdoc that the function is the class constructor, you can use @this
to define what this
refers to:
/**
* @classdesc My little class.
*
* @class
* @memberof module:MyModule
* @name MyLittleClass
* @param {*} myParam Constructor parameter.
*/
// Somewhere else, the constructor is defined:
/**
* @this module:MyModule.MyLittleClass
*/
function(myParam) {
/**
* Instance property.
* @type {string}
*/
this.myProp = 'foo';
}
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