关于使用jsDoc记录嵌套数组和对象数据的问题

Questions about documenting nested array and object data with jsDoc

本文关键字:对象 数据 问题 数组 于使用 jsDoc 记录 嵌套      更新时间:2023-09-26

如何使用jsdoc格式化嵌套数组和对象?

这是我最好的猜测:

an_obj = { 
        username1 : [
            {
                param1 : "value 1-1-1",
                param2 : "value 1-1-2",
                optional_nested : "1-1--2"
            },
            {
                param1 : "value 1-2-1",
                param2 : "value 1-2-2"
            },
        ],
        username2 : [
            {
                param1 : "value 2-1-1",
                param2 : "value 2-1-2"
            },
            {
                param1 : "value 2-2-1",
                param2 : "value 2-2-2",
                optional_nested : "2-2--2"              
            }
        ]
    }
}

/**
 * A function description.
 * @param {Object} obj
 * @param {Object} obj.username  This is not the object name, but a name type. 
 * @param {Array}  obj.username.array Desc...  using [] would conflict with optional params.
 *                                    However this could be confused with an object called array.
 * @param {String} obj.username.array.param1 Desc... This is the object name rather than a type.
 * @param {String} obj.username.array.param2 Desc... 
 * @param {String} obj.username.array.[optional_param] Desc... 
 */
var myFunc = function(obj){
    //...
};
myFunc(an_obj);

如何指示一个对象是由一种字符串索引的?

如何定义嵌套数组?

也不确定在可选参数中放方括号的位置。

您可以尝试这样做:(如下所示http://code.google.com/p/jsdoc-toolkit/wiki/TagParam)

/**
* @param {String[]} obj.username.array
*/

这应该将obj.username.array声明为字符串数组。您使用的是jsdoc还是jsdoc3?

我建议您查看一下。我可能会这样写:

//{Object{username:<Array<Object{param1:String, param2:String,[optional_nest]:string}>>}}