开发者

Documenting a javascript class with prototypes in a namespace using jsdoc-toolkit

开发者 https://www.devze.com 2023-02-23 22:34 出处:网络
I\'m trying very hard to document code in the format below using jsdoc-toolkit. It looks to me like the tags I\'ve used should produce the desired result but it doesn\'t. Instead it warns that Class i

I'm trying very hard to document code in the format below using jsdoc-toolkit. It looks to me like the tags I've used should produce the desired result but it doesn't. Instead it warns that Class is undocumented (because it is only defined inside the closure) and doesn't include Class in list of members of namespace.

I'm would like to document this without resorting to using the @name tag if possible. Can anyone help?

/**
 * @namespace The original namespace
 */
var namespace = function () {
    // private
    /**
     * @private
     */
    function _privateMethod () {

    };

    /**
     * This is the detail about the constructor
     * @class This is the detail about the class
     * @param {Object} argone The first argument
     * @param {Object} argtwo The second argument
     */
    var Class = function (argone, argtwo) {
        /**
         * A public member variable
         */
        this.member = "a member";
    };

    /**
     * A public method
开发者_如何转开发     * @param {Object} argone The first argument
     */
    Class.prototype.publicMethod = function (argone) {

    };

    return /** @lends namespace */ {
        Class: Class
    }
}();


I tried a bunch of different things and this was the best I could come up with.

The first part...documenting the publicMethod on Class. First make Class a memberOf namespace and then use @lends on the Class.prototype. Example:

/**
 * @namespace The original namespace
 */
var namespace = function () {
    // private
    /**
     * @private
     */
    function _privateMethod () {

    };

    /**
     * This is the detail about the constructor
     * @class This is the detail about the class
     * @memberOf namespace
     * @param {Object} argone The first argument
     * @param {Object} argtwo The second argument
     */
    var Class = function (argone, argtwo) {
        /**
         * A public member variable
         */
        this.member = "a member";
    };

    Class.prototype = 
    /** @lends namespace.Class */ 
    {
        /** a public method
          * @param {Object} argone The first argument
        */
        publicMethod: function (argone) {

        }
    };

    return {
        Class: Class
    }
}();

Now, the second part...getting Class to show up as on the namespace. I'm not sure how to do that...sorry! It will show up as namespace.Class in the class index.


Just as a tip: jsdoc 2 is full of bugs and bad practices.
Consider trying JSDOC3 -> https://github.com/jsdoc3/jsdoc or no jsdoc at all depending the nature of the project.

0

精彩评论

暂无评论...
验证码 换一张
取 消