How to document the properties of the object in the JSDoc 3 tag: @this

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 jsdoc@3.3.0-alpha3 looks like this:

JSDoc3 output

See also:

  • JSDoc namepaths
  • @instance tag
  • @readonly tag
  • @type tag

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)