Kesha Seyfert
Kesha Seyfert

Reputation: 38

JSDoc and factory

I have something like this:

var make_point = function (x, y) {
  return {
    x: x,
    y: y,
    length: function () {
      return Math.sqrt(this.x * this.x + this.y * this.y);
    }
  }
}

What is the best way to create documentation for this using jsdoc?

Upvotes: 0

Views: 248

Answers (1)

Razem
Razem

Reputation: 1451

You should use typedef and then use it as a return type of the function:

/**
 * @typedef Point
 * @property {Number} x
 * @property {Number} y
 * @property {Function} length
 * @property {Point~getProjection} getProjection
 */

/**
 * @callback Point~getProjection
 * @param {Object} axes
 * @returns {Object}
 */

/**
 * @param {Number}
 * @param {Number}
 * @returns {Point}
 */
var make_point = function (x, y) {
  // ...
}

Or you can use object type:

/**
 * @param {Number}
 * @param {Number}
 * @returns {{x: Number, y: Number, length: Function}}
 */
var make_point = function (x, y) {
  // ...
}

Upvotes: 1

Related Questions