javascript JSDoc:如何记录父“类”的“选项”对象文字?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10683430/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 10:40:53  来源:igfitidea点击:

JSDoc: How do I document the "options" object literal for a parent "class"?

javascriptjsdoc

提问by billc.cn

I am using jQuery's $.widget()base "class" which provides an option()method. Since the method is not in my code, I don't have a place to document the argument.

我正在使用 jQuery 的$.widget()基本“类”,它提供了一种option()方法。由于该方法不在我的代码中,因此我没有地方记录该参数。

I tried to put jsDoc on the fields in the default options literal, but they're simply not picked up. Then I tried to use the @classand @lendstags on the same object literal, but this may be quite confusing as the object literal is not really a class.

我试图将 jsDoc 放在默认选项文字中的字段上,但它们根本没有被选中。然后我尝试在同一个对象文字上使用@class@lends标签,但这可能会很混乱,因为对象文字并不是真正的类。

Another alternative I've experimented is to put something like @param options.field descriptionin the constructor's jsDoc. However, this has the disadvantage of separating the documentation from the code. Also, the constructor don't actually have an argument called optionsas it's all handled by jQuery.

我尝试过的另一种选择是@param options.field description在构造函数的 jsDoc 中放入类似的内容。但是,这样做的缺点是将文档与代码分开。此外,构造函数实际上没有调用参数,options因为它全部由 jQuery 处理。

How does you Javascript gurus handle this? Should a new tag be proposed?

Javascript 大师如何处理这个问题?是否应该提出新标签?

回答by Jamie Mason

If I understand your question correctly, you have a function that takes an options object and you want to document all of its members?

如果我正确理解你的问题,你有一个接受选项对象的函数,你想记录它的所有成员?

A rough example of how to do that in JSDoc is as below:

如何在 JSDoc 中执行此操作的粗略示例如下:

/**
 * @description
 * Compliment someone on their something.
 *
 * @param {Object} options
 * @param {String} options.name    A person's name
 * @param {String} options.feature A person's property
 */
function flatter (options) {
  options = options || {};
  console.log('%s, loving your %s!', options.name, options.feature);
}