I need to put a function in a javascript object, how do I add a JSDoc comment in this case?
/**
* @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.
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.
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.
And I also want to express that this function returns a String.
Use @function to define the function first, and then use the name of the function anywhere you need it, example:
/**
* 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.