How can I properly document instance instances added via Object.defineProperties?

I have a class that defines several properties of an instance through Object.defineProperties, and it is very difficult for me to get JSDoc 3 to recognize that they belong to their class.

Here is 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 a conclusion for mymodule, Example, fooand bar, but not foobar. If I remove the tag @memberoffor foobar, it will be registered as global. I tried @memberof mymmodule~Exampleadding @lendsto the call Object.definePropertiesand the object passed to it, and converted it to Object.defineProperty, but the results are not changed.

How can I document foobaras belonging Example?

+5
3

, , , , - @memberof , JSDoc, , , , pathpath, . :

/** A foo and a bar
  *
  * @type String
  * @instance
  * @memberof module:mymodule~Example
  */
+8

- @memberOf!. "O" "bang"! "

/**
 * Description
 * @memberOf! MyClass
 * @type {String}
 */
var myString;
0

You can also try the @lends annotation instead of @memberOf as follows:

Object.defineProperties(this, /** @lends Example# */{
    /** A foo and a bar */
    foobar: { enumerable: false, value: foo + bar, writable: false }
});

Don't forget the sharp character after the class name to indicate that jsdoc members are instance members, not static members.

0
source

All Articles