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.
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
@borrowstag in the Singleton doc comment:But this has several ramifications, good and bad:
foofunction is markedstatic. This is probably a good thing, as it seems to be accurate as I understand your code.@lendstag entirely, unless you want to include it for clarity. If all methods are listed as@borrowson 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
_footofoo, but it will display_fooin the documentation page as well:Probably the best workaround is simply to forget
@borrowsentirely and explicitly name_fooasSomething.Singleton.fooin the doc comment, marking it as a public function (you could dispense with@publicif 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).