[英]JSDOC: How to document a function within of simple object
I need to document a simple object and I'm failing to find a documentation or tutorial how to document @param
and @returns
for the inner methods.我需要记录一个简单的 object 并且我找不到如何记录内部方法的
@param
和@returns
的文档或教程。 If I put them above the respective method ( xyz
), they are ignored, if I put them above the object, @param
is not assigned (or I have no idea how to assign it here).如果我将它们放在相应的方法(
xyz
)之上,它们将被忽略,如果我将它们放在 object 之上,则不会分配@param
(或者我不知道如何在这里分配它)。
Let's say it's a simple object, like this:假设它是一个简单的 object,如下所示:
export const foo = {
abc: 'A string',
xyz: (x) => {
return x + '!'
}
}
I expected something like this should work:我希望这样的事情应该有效:
/**
* @module FooModule
*/
/**
* @type {object}
*/
export const foo = {
/**
* @property {string} abc - some property
*/
abc: 'A string',
/**
* @property {function} xyz - some method
* @param {string} x - source string
* @returns {string} - exclamation mark added
*/
xyz: (x) => {
return x + '!'
}
}
But it doesn't work, obviously.但这显然不起作用。 I've found a similar question here but the solution is wrong, it doesn't work at all.
我在这里发现了一个类似的问题,但解决方案是错误的,它根本不起作用。 How should this be done correctly, so that I get a module
FooModule
, a global constant foo
with foo.abc
property and foo.xyz
method (incl. @param
and @returns
) in the output JSDoc?这应该如何正确完成,以便我在 output JSDoc 中获得一个模块
FooModule
,一个具有foo.abc
属性和foo.xyz
方法(包括@param
和@returns
)的全局常量foo
?
Can it be done?可以做到吗? If yes, can it be done without
@typedef
ing all functions like this?如果是,可以在没有
@typedef
所有函数的情况下完成吗?
It seems the latest answer to other question found the problem.似乎其他问题的最新答案发现了问题。 It's not in the JSDoc syntax, but in the javascript itself.
它不在 JSDoc 语法中,而是在 javascript 本身中。 It seems JSDoc's
@module
can't be used with the export
directive.似乎 JSDoc 的
@module
不能与export
指令一起使用。 If @module
is removed, the documentation works as expected.如果删除了
@module
,文档将按预期工作。 If @module
is used, the export
must be replaced by如果使用
@module
,则export
必须替换为
module.exports = foo
at the end.在最后。 Then the JSDoc build works fine.
然后 JSDoc 构建工作正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.