问题描述
我正在使用jQuery的$.widget()
基类",它提供了一个option()
方法.由于该方法不在我的代码中,因此我没有地方记录该参数.
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.
我尝试将jsDoc放在默认选项文字中的字段上,但是根本没有将它们拿起.然后,我尝试在同一对象文字上使用@class
和@lends
标记,但是由于对象文字不是真正的类,因此这可能会造成混淆.
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 @class
and @lends
tags on the same object literal, but this may be quite confusing as the object literal is not really a class.
我尝试过的另一种替代方法是将类似@param options.field description
的内容放入构造函数的jsDoc中.但是,这具有将文档与代码分开的缺点.另外,构造函数实际上没有名为options
的参数,因为它全部由jQuery处理.
Another alternative I've experimented is to put something like @param options.field description
in 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 options
as it's all handled by jQuery.
您的Javascript大师如何处理此问题?是否应该提出一个新标签?
How does you Javascript gurus handle this? Should a new tag be proposed?
推荐答案
如果我正确理解了您的问题,那么您有一个使用options对象的函数,并且您想记录其所有成员?
If I understand your question correctly, you have a function that takes an options object and you want to document all of its members?
有关如何在JSDoc中执行此操作的大致示例如下:
A rough example of how to do that in JSDoc is as below:
/**
* @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);
}
这篇关于JSDoc:如何记录“选项"父“类"的对象字面量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!