我有一个 JavaScript 类,它接受一个具有定义的属性集的 Object 类型的参数,当我像这样注释它时,Closure 编译器很高兴:
@constructor
@param {{ subview:BaseView, el:(jQuery|Element), title:String }} options
var MyView = function(options){ }
我想使 title
键可选,并将 title
值传递给我类的某些实例,并在该键不存在时实现回退行为,所以我注释了我的类:
@constructor
@param {{ subview:BaseView, el:(jQuery|Element), title:String= }} options
var MyView = function(options){ }
现在 Closure Compiler 报错了:
WARNING - Bad type annotation. expected closing }
我检查过 Annotating JavaScript for the Closure Compiler ,但我没有看到任何一行描述这种用例。
最佳答案
@param {{ subview:BaseView, el:(jQuery|Element), title:(string|undefined) }} 选项
关于javascript - 如何在 JSDoc 中使用可选属性注释匿名对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25773222/