如何记录一个函数参数,它本身就是一个在 JavaScript 中带有参数的函数?
How to docstring a function arugument which is itself a function with arguments in JavaScript?
我如何记录本身是函数的参数?
示例:
/**
*
* @param secondFunction // I want to say this should be a function that accepts a number
*/
function firstFunction(secondFunction) {
const a = 1;
secondFunction(a);
}
干杯!
回调函数
如果参数接受回调函数,您可以使用@callback
tag定义回调类型,然后将回调类型包含在@param
标签中。
接受回调的参数
/**
* This callback type is called `secondFunction` and is displayed as a global symbol.
*
* @callback secondFunction
* @param {number} a
*/
/**
* executes secondFunction
* @param {secondFunction} secondFunction - The callback
*/
function firstFunction(secondFunction) {
const a = 1;
secondFunction(a);
};
您可以将参数的类型定义为您希望传递的函数签名:
/** Calls second function with 1
* @param {(a:number)=>void} secondFunction
*/
function firstFunction(secondFunction) {
const a = 1;
secondFunction(a);
};
我如何记录本身是函数的参数?
示例:
/**
*
* @param secondFunction // I want to say this should be a function that accepts a number
*/
function firstFunction(secondFunction) {
const a = 1;
secondFunction(a);
}
干杯!
回调函数
如果参数接受回调函数,您可以使用@callback
tag定义回调类型,然后将回调类型包含在@param
标签中。
接受回调的参数
/**
* This callback type is called `secondFunction` and is displayed as a global symbol.
*
* @callback secondFunction
* @param {number} a
*/
/**
* executes secondFunction
* @param {secondFunction} secondFunction - The callback
*/
function firstFunction(secondFunction) {
const a = 1;
secondFunction(a);
};
您可以将参数的类型定义为您希望传递的函数签名:
/** Calls second function with 1
* @param {(a:number)=>void} secondFunction
*/
function firstFunction(secondFunction) {
const a = 1;
secondFunction(a);
};