I have a class which defines a few instance properties via Object.defineProperties and I’m having great difficulty getting JSDoc 3 to recognize that they belong to their class.
Here’s a simplified version of what I’m working with:
/** @exports mymodule */
function mymodule(exports) {
/** @constructor
* @param {String} foo A foo.
* @param {String} bar A bar.
* @classdesc Has a foo and a bar.
*/
function Example(foo, bar) {
Object.defineProperties(this, {
/** A foo and a bar
* @memberof Example
*/
foobar: { enumerable: false, value: foo + bar, writable: false }
});
}
exports.Example = Example;
}
When I run JSDoc, I get output for mymodule, Example, foo, and bar, but not foobar. If I remove the @memberof tag for foobar, it get registered as a global. I’ve tried @memberof mymmodule~Example, adding @lends to both the Object.defineProperties call and the object passed to it, and converting it to Object.defineProperty, but the results don’t change.
How can I document foobar as belonging to Example?
After digging through every example I could find, I finally assembled the necessary incantation —
@memberofis indeed the trick, but JSDoc seems to require that modules being used in namepaths be explicitly marked as such. The following worked perfectly: