枚举作为 JSDoc 中的 @param 类型
是否可以像下面的示例一样为 JSDoc @param
类型声明使用枚举?
Is it possible to use an enum for the JSDoc @param
type declaration like in the following example?
/**
* @enum { Number }
*/
var TYPES = {
TYPE_A: 1,
TYPE_B: 2
}
/**
* @param { TYPES } type
*/
function useTypesEnum( type ) {
}
如果我对 JavaScript 使用 Eclipse 等 IDE,应该不会发出警告?
If I use an IDE like Eclipse etc. for JavaScript, there should no warning be raised?
推荐答案
JsDoc 注释对 JavaScript 代码没有影响.它确实影响的是一些旨在使用该信息的工具.使用 JsDoc 注释的两个工具是 文档生成器 和 Google Closure Compiler.
JsDoc comments have no impact on JavaScript code. What it does influence is some tools designed to use that information. Two of the tools that work with JsDoc comments are the documentation generator and the Google Closure Compiler.
我对 JsDoc3 不是特别熟悉,其中添加了 @enum 标记,但我认为它与任何其他类型一样工作.
I am not particularly familiar with JsDoc3, in which the @enum tag has been added, but i would assume it works just as any other type.
闭包编译器也能正确识别枚举,您可以像示例中提到的那样使用它并获得编译器的所有好处(例如:类型检查).
The Closure Compiler also recognizes the enum correctly and you can use it just like you mentioned in the example and get all the benefits of the compiler (ex: type checking).
相关文章