[英]Inquiry to write function to javascript Object JSDoc property
I need to put a function in a javascript object, how do I add a JSDoc comment in this case?我需要在 javascript 对象中放置一个函数,在这种情况下如何添加 JSDoc 注释?
/**
* @typedef {Object} testObj
* @property {!String} testName - testName
* @property {?Function} [testFunction=null] - testFunction
*
*/
var testObj = {
testName:null,
testFunction:null
}
In this form, null is the default value for the function, so it is expressed like this.在这种形式中,null 是函数的默认值,所以它是这样表示的。
I just want to ask if it is enough to write only the @property {?Function}
and write the parameter in the Object part, or if there is another way.我只想问是否只写
@property {?Function}
并在Object部分写参数是否足够,或者是否有其他方法。
In the testFunction above, I want to show in JSDoc that a function with parameters {Number} a, {number} b, {Object} c
is put in. If there is a way, I would appreciate it if you let me know.在上面的 testFunction 中,我想在 JSDoc 中显示一个带有参数
{Number} a, {number} b, {Object} c
的函数。如果有办法,如果你告诉我,我将不胜感激。 And I also want to express that this function returns a String
.而且我还想表达这个函数返回一个
String
。
Use @function
to define the function first, and then use the name of the function anywhere you need it, example:先使用
@function
定义函数,然后在需要的任何地方使用函数的名称,例如:
/**
* A test function
*
* @function testFunction
* @param {number} a Number a
* @param {number} b Number b
* @param {Object} c Object c
* @returns {string} Returns a string
*/
/**
* A test Object
*
* @typedef {Object} testObj
* @property {!string} testName The Test Name
* @property {?testFunction} testFunction The Test Function
*/
const testObj = {
testName: null,
testFunction: null,
}
Just tested it with jsdoc and the documentation is generated correctly with the link in the testFunction property.刚刚使用jsdoc对其进行了测试,并且使用 testFunction 属性中的链接正确生成了文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.