小编Sha*_*rya的帖子

如何使用有限的可能值记录jsdoc中的字符串类型

我有一个接受一个字符串参数的函数.此参数只能包含一些已定义的可能值.记录相同内容的最佳方法是什么?应该将shapeType定义为enum或TypeDef还是其他什么?

Shape.prototype.create = function (shapeType) {
    // shapeType can be "rect", "circle" or "ellipse"...
    this.type = shapeType;
};

Shape.prototype.getType = function (shapeType) {
    // shapeType can be "rect", "circle" or "ellipse"...
    return this.type;
};
Run Code Online (Sandbox Code Playgroud)

问题的第二部分shapeType是在文件中不知道可能的值,它定义shapeType为您建议的任何内容.有几个开发人员提供了多个文件,可能会添加可能的值shapeType.

PS:我正在使用 jsdoc3

code-documentation google-closure google-closure-compiler jsdoc

69
推荐指数
4
解决办法
2万
查看次数

将子属性添加到 jsdoc 中的现有属性列表

我正在尝试自动化 JS 库中的特定模块,但陷入了我想要定义一组属性的点(假设一个对象作为类的构造参数)。

/**
 * This function initiates world peace!
 * @constructor
 * @param {object}  defaults        - The options to initiate peace.
 * @param {number}  defaults.issues - The number of issues being taken up.
 * @param {string}  defaults.source - The name of the location where process starts.
 */
 var WorldPeace = function (defaults) {
     // code here
 };
Run Code Online (Sandbox Code Playgroud)

如果构造的所有属性都在一个位置定义,那就太好了。不幸的是,我的代码有许多模块有助于构建属性。可以说,在代码的其他部分(在后面的文件中)会导致具有更多属性

 * @param {Date} defaults.start  - The date when the process started.
 * @param {Date} defaults.stop   - The date when the process …
Run Code Online (Sandbox Code Playgroud)

javascript code-documentation google-closure google-closure-compiler jsdoc

5
推荐指数
1
解决办法
1520
查看次数