10

如何使用 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);

如何指示对象由某种字符串索引?

如何定义嵌套数组?

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

4

2 回答 2

1

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

//{Object{username:<Array<Object{param1:String, param2:String,[optional_nest]:string}>>}}
于 2012-07-30T09:35:14.740 回答
1

您可以尝试这样做:(此处指定http://code.google.com/p/jsdoc-toolkit/wiki/TagParam

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

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

于 2012-08-09T10:17:43.647 回答