我做了一些测试,我有好消息和坏消息:)。好消息是,它看起来像你可以得到这个通过将@borrows
标签在辛格尔顿文档注释工作:
/**
* This is the singleton.
*
* @namespace Something.Singleton
* @borrows Something.Singleton-_foo as foo
*/
Something.Singleton = (function() {
// etc
})());
但是这有几个后果,有好有坏:
- 的
foo
功能标记为static
。这可能是一件好事,因为我了解你的代码似乎是准确的。
- 由于目前显示的代码(即单身人士等没有更多的方法),您可以完全省去
@lends
标签,除非为了清晰起见而包含它。如果所有方法在顶级单例名称空间中都列为@borrows
,则不需要在返回的对象中进一步记录它们。再次,这可能是一件好事。
- 坏消息是,除非借用的方法明确标记为
@public
,否则我无法使其工作,这使得它在文档中冗余显示。我认为这是不可避免的 - 如果jsdoc-toolkit认为这个方法是私有的,它不会创建文档,所以你不能引用它(我得到WARNING: Can't borrow undocumented Something.Singleton-_foo.
)。如果该方法是公开的,它将显示在文档中。
所以此工程:
/**
* This is the singleton.
*
* @namespace Something.Singleton
* @borrows Something.Singleton-_foo as foo
*/
Something.Singleton = (function() {
/**
* @public
* Foo method.
*
* @return {String} this method always returns with <code>bar</code>
*/
function _foo() { return "bar"; }
return {
foo: _foo
};
}());
...在这副本_foo
的文档以foo
,但它会在文档页面显示_foo
还有:
Method Summary
<inner> _foo()
<static> Something.Singleton.foo()
也许是最好的解决方法是简单地忘记@borrows
完全和在文档注释中明确命名_foo
为Something.Singleton.foo
,将其标记为公共功能(你可以用@public
免除,如果你没有名字带有下划线的内部函数,但是这告诉jsdoc的工具包把它当作私人除非特别指出):
/**
* This is the singleton.
*
* @namespace Something.Singleton
*/
Something.Singleton = (function() {
/**
* @name Something.Singleton#foo
* @public
* @function
* Foo method.
*
* @return {String} this method always returns with <code>bar</code>
*/
function _foo() { return "bar"; }
return {
foo: _foo
};
}());
这将生成您正在查找的代码文档,并将注释放在与其相关的实际代码旁边。它不能完全满足个人需要让计算机完成所有工作 - 你必须在评论中非常明确 - 但我认为它与原来的一样清楚,如果不是更多的话,我认为它的维护要多得多(即使在你最初的例子中,如果你改名为Something.Singleton
,你将不得不改变你的所有文档评论)。
最后一个例子非常适合。谢谢! – 2011-04-14 08:31:57
避免让它静态顺便更好。 – 2011-04-14 09:08:51
好吧,我发现它'@name Something.Singleton#methodName'是解决方案。 – 2011-04-14 09:13:03