使用jsdoc-toolkit记录具有原型的JavaScript命名空间类

10

我正在尝试使用jsdoc-toolkit以以下格式记录代码。看起来我使用的标签应该会产生期望的结果,但实际上没有。它警告说Class没有文档(因为它仅在闭包内定义),并且不在命名空间成员列表中包括Class。

如果可能的话,我想避免使用@name标签来记录。有人能帮忙吗?

/**
 * @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
    }
}();

2
你使用的 JSDoc Toolkit 版本是什么来生成文档的? - Stephen
2个回答

4
我尝试了很多方法,这是我能想到的最好的。
第一部分...记录在Class上的publicMethod。首先将Class作为namespace的一个memberOf,然后在Class.prototype上使用@lends。例如:
/**
 * @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
    }
}();

现在,第二部分是如何让Class显示为namespace上的内容。我不确定如何做...抱歉!在类索引中将显示为namespace.Class

0

作为一个提示:jsdoc 2 充满了错误和不良实践。
考虑尝试 JSDOC3 -> https://github.com/jsdoc3/jsdoc 或者根据项目的性质完全不使用 jsdoc。


2
JSDoc 3也不起作用。整个工具有点荒谬。 - Thomas Urban
我正在使用通过npm安装的jsdoc3,但它也忽略了原型。 - Jake Wilson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接