Search code examples
javascriptjsdocobject-literaljsdoc3

Why does this object literal not render to JSDoc?


I have the following JavaScript.

It is a RequireJS module that has its functions namespaced into an object literal. I referred to: How do I JSDoc A Nested Object's Methods? to find out how to mark up the JSDoc notations.

I run JSDocs 3.3.0-beta3 with private: true in a grunt task but on the modules page there are no private methods or arguments for the publich method.

/**
 * A module doing a lot of Foo.
 * @module Foo
 * @requires jquery
 * @author Markus Falk
 */
define(['jquery'], function($) {

  'use strict';

  /**
   * @property {Object} Container
   */
  var Foo = {
    /**
     * Caches all jQuery Objects for later use
     * @function
     * @private
     */
    _cacheElements: function() {
      this.$foo = $('.foo');
    },
    /**
     * inits the app and returns the Message Text
     * @function
     * @public
     * @param {Object} msg - The message.
     * @param {string} msg.text - The message's Text.
     * @param {string} msg.author - The message's author.
     * @returns {String} Sentence with given message.text
     */
    init: function(msg) {
      this._cacheElements();
      return "Say " + msg.text;
    }
  };

  return /** @alias module:Foo */ {
    /** init */
    init: Foo.init
  };
});

Here is the output of this JSDoc code:

JSDocs


Solution

  • Try @function init and @function _cacheElements

    /**
     * A module representing a Foo.
     * @module Foo
     * @requires jquery
     * @author Markus Falk
     */
    define(['jquery'], function($) {
    
      'use strict';
    
      /**
       * @property {Object} Container
       */
      var Foo = {
        /**
         * Caches all jQuery Objects for later use
         * @function _cacheElements
         * @private
         */
        _cacheElements: function() {
          this.$foo = $('.foo');
        },
        /**
         * inits the app and returns the Message Text
         * @function init
         * @public
         * @param {Object} msg - The message.
         * @param {string} msg.text - The message's Text.
         * @param {string} msg.author - The message's author.
         * @returns {String} Sentence with given message.text
         */
        init: function(msg) {
          this._cacheElements();
          return "Say " + msg.text;
        }
      };
    
      return /** @alias module:Foo */ {
        /** init */
        init: Foo.init
      };
    });
    

    enter image description here