You can use a namepath to document an inner member. Per the documentation:
Namepaths in JSDoc 3
When referring to a JavaScript variable that is elsewhere in your documentation, you must provide a unique identifier that maps to that variable. A namepath provides a way to do so and disambiguate between instance members, static members and inner variables.
Basic Syntax Examples of Namepaths in JSDoc 3
myFunction
MyConstructor
MyConstructor#instanceMember
MyConstructor.staticMember
MyConstructor~innerMember // note that JSDoc 2 uses a dash
Since you want to refer to the returned inner Function inside foo, you must use the very last option which documents an inner member of a function.
To use namepaths, you must use an identifier so JSDoc can identify the member, and this is achieved through declaring a variable as mentioned in the documentation. You can define your return value as a variable and return the variable. Thus:
/**
* @param {String} data
* @returns {foo~newFunction}
*/
const foo = data => {
let functionString = 'return data;'
/**
* Notice the idenfier newFunction given to the member
* You can now document the function here
*/
let newFunction = Function('data', functionString)
return newFunction
}
With the above, we define the former return value as a variable named newFunction. Consequently, we can use namepaths to reference it as foo~newFunction as its now an inner member of foo, and then set it as the return value of foo. You can then return newFunction.