JSDoc 和 JavaScript 属性 getter 和 setter
我希望我的代码(如下所示)可以生成使用 JSDoc(v2.4.0) 描述对象文字的每个属性的文档,但它不起作用。有谁知道如何使用 JSDoc 从使用 getter/setter 的代码生成文档?
/** Enum of days of week. */
var Day = {
/** Sunday. */
get Sun() { return 0; },
/** Monday. */
get Mon() { return 1; },
/** Thuesday. */
get Tue() { return 2; },
/** Wednesday. */
get Wed() { return 3; },
/** Thursday. */
get Thu() { return 4; },
/** Friday. */
get Fri() { return 5; },
/** Saturday. */
get Sat() { return 6; }
}
I was hoping that my code, something like below, could generate documents describing each property of the object literal with JSDoc(v2.4.0), but it did not work. Does anyone know how to work with JSDoc to generate documents from code that uses getter/setter?
/** Enum of days of week. */
var Day = {
/** Sunday. */
get Sun() { return 0; },
/** Monday. */
get Mon() { return 1; },
/** Thuesday. */
get Tue() { return 2; },
/** Wednesday. */
get Wed() { return 3; },
/** Thursday. */
get Thu() { return 4; },
/** Friday. */
get Fri() { return 5; },
/** Saturday. */
get Sat() { return 6; }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
@type
记录 JavaScriptget
和set
访问器。类似下面的内容应该适用于 JSDoc:这将每个属性记录为具有
number
类型的成员。Use
@type
to document JavaScriptget
andset
accessors. Something like the following should work with JSDoc:This documents each property as a member with a type of
number
.您可以使用 jQuery 风格的 getter/setter 方法:
我刚刚与 Michael 本人讨论了这个问题。由于非常酷,在 jsDoc3 (https://github.com/micmath/jsdoc) 中这是可能的特征。可以堆叠多个文档块(一个用于 getter,一个用于 setter):
http://groups.google.com/group/jsdoc-users/browse_thread/thread/d4c7794bc8f6648e/94df7339e1fc4c91#94df7339e1fc4c91
You could use jQuery style getter / setter methods:
I have just been discussing this very issue with Michael himself. It is possible in jsDoc3 (https://github.com/micmath/jsdoc) due to a very cool feature. It is possible to stack multiple docblocks (one for getter and one for setter):
http://groups.google.com/group/jsdoc-users/browse_thread/thread/d4c7794bc8f6648e/94df7339e1fc4c91#94df7339e1fc4c91