Kerim Güney
Kerim Güney

Reputation: 1258

How to make JSDoc recognize anonymous function assigned to object property? (example code included)

I have a file called example.js containing the following content. When I run

jsdoc example.js

I get an ./out folder as expected but the resulting documentation does not contain foo.greeting, only greeting.

const foo = {};

/**
 * greets with name in text
 * @param {string} name  - name
 * @returns {string} - an IPC response object
 */
foo.greeting = (name) => {
  return 'hello, ' + name;
};

/**
 * greets with name in text
 * @param {string} name  - name
 * @returns {string} - an IPC response object
 */
const greeting = (name) => {
  return 'hello, ' + name;
};

Is it possible to make jsdoc recognize the anonymous function assignment to the object property?

I am currently using JSDoc 3.6.6.

Upvotes: 2

Views: 510

Answers (1)

lonesomeday
lonesomeday

Reputation: 237817

Yes, you can do this by tagging it with @function:

/**
 * @function greeting
 * @description greets with name in text
 * @param {string} name  - name
 * @returns {string} - an IPC response object
 */
foo.greeting = (name) => {
  return 'hello, ' + name;
};

Whether this produces exactly what you're looking for, it's hard to say, but it does at least produce something.

Upvotes: 2

Related Questions