如何在 jsdoc-toolkit 中包含已经记录的方法?
我有一个使用闭包方法创建的 JavaScript 单例对象:
/**
* This is the singleton.
*
* @namespace window.Something.Singleton
*/
window.Something.Singleton = (function() {
/**
* Foo method.
*
* @return {String} this method always returns with <code>bar</code>
*/
function _foo() { return "bar"; }
/**
* @lends window.Something.Singleton#
*/
return {
/**
* @borrows window.Something-_foo
* @function
*/
foo: _foo
};
}());
但是 jsdoc-toolkit 没有生成我想要的从 _foo
方法到 foo
方法的继承文档。
如果我写 @see
而不是 @borrows
它可以工作(插入正确方法的链接),但我不想复制和粘贴 < code>foo 方法也有公共文档。
I have a JavaScript singleton object created with closure method:
/**
* This is the singleton.
*
* @namespace window.Something.Singleton
*/
window.Something.Singleton = (function() {
/**
* Foo method.
*
* @return {String} this method always returns with <code>bar</code>
*/
function _foo() { return "bar"; }
/**
* @lends window.Something.Singleton#
*/
return {
/**
* @borrows window.Something-_foo
* @function
*/
foo: _foo
};
}());
But the jsdoc-toolkit does not generate the inherited documentation from _foo
method to the foo
method what I would like to have.
If I write @see
instead of @borrows
it works (inserts a link to the correct method), but I don't want to copy&paste the documentation for the foo
method to have a public documentation as well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我做了一些测试,有好消息和坏消息:)。好消息是,看起来您可以通过将
@borrows
标记放入 Singleton 文档注释中来使其工作:但这有几个后果,好的和坏的:
foo 函数被标记为
static
。这可能是一件好事,因为根据我理解你的代码,它似乎是准确的。@lends
标记,除非您为了清楚起见而想要包含它。如果所有方法都在顶级单例命名空间中列为@borrows
,那么您无需在返回的对象中进一步记录它们。再说一次,这可能是一件好事。@public
,否则我无法让它工作 - 这使得它在文档中冗余地显示。我认为这是不可避免的 - 如果 jsdoc-toolkit 认为该方法是私有的,它不会创建文档,因此您无法引用它(我得到警告:无法借用未记录的 Something.Singleton-_foo。 )。如果该方法是公共的,它将显示在文档中。
所以这是有效的:
...它将
_foo
的文档复制到foo
,但它也会在文档页面中显示_foo
:最好的解决方法可能就是完全忘记
@borrows
并在文档注释中明确将_foo
命名为Something.Singleton.foo
,将其标记为作为公共函数(如果您没有使用下划线命名内部函数,则可以省略@public
,但这会告诉 jsdoc-toolkit 将其视为私有函数,除非另有说明):这将产生您正在查找的代码文档,并将注释放在与其相关的实际代码旁边。它并不能完全满足让计算机完成所有工作的需要 - 你必须在评论中非常明确 - 但我认为它与你最初的内容一样清晰,甚至更清晰,而且我不这么认为不要认为这需要更多的维护(即使在最初的示例中,如果您重命名了
Something.Singleton
,您也必须更改所有文档注释)。I did some tests, and I have good news and bad news :). The good news is that it looks like you can get this to work by putting the
@borrows
tag in the Singleton doc comment:But this has several ramifications, good and bad:
foo
function is markedstatic
. This is probably a good thing, as it seems to be accurate as I understand your code.@lends
tag entirely, unless you want to include it for clarity. If all methods are listed as@borrows
on the top singleton namespace, then you don't need to further document them in the returned object. Again, this is probably a good thing.@public
- which makes it show up, redundantly, in the documentation. I think this is unavoidable - if jsdoc-toolkit thinks the method is private, it won't create documentation, so you can't refer to it (I getWARNING: Can't borrow undocumented Something.Singleton-_foo.
). If the method is public, it gets displayed in the documentation.So this works:
...in that it copies the documentation for
_foo
tofoo
, but it will display_foo
in the documentation page as well:Probably the best workaround is simply to forget
@borrows
entirely and explicitly name_foo
asSomething.Singleton.foo
in the doc comment, marking it as a public function (you could dispense with@public
if you didn't name your inner function with an underscore, but this tells jsdoc-toolkit to treat it as private unless told otherwise):This will produce the code documentation you're looking for, and puts the comment next to the actual code it relates to. It doesn't fully satisfy one's need to have the computer do all the work - you have to be very explicit in the comment - but I think it's just as clear, if not more so, than what you had originally, and I don't think it's much more maintenance (even in your original example, you'd have to change all your doc comments if you renamed
Something.Singleton
).http://code.google.com/p/jsdoc-toolkit/wiki/TagBorrows
@borrows otherMemberName as thisMemberName
otherMemberName
- 必需:其他成员的名称路径。thisMemberName
- 必需:该成员在此类中分配的新名称。Remote#transfer 的任何文档也将显示为 SpecialWriter#send 的文档。
http://code.google.com/p/jsdoc-toolkit/wiki/TagBorrows
@borrows otherMemberName as thisMemberName
otherMemberName
- Required: the namepath to the other member.thisMemberName
- Required: the new name that the member is being assigned to in this class.Any documentation for Remote#transfer will also appear as documentation for SpecialWriter#send.