说你有这个功能:
/**
* doSomething description
* @param {function} fn - A function that accepts an argument.
*/
function doSomething( fn ) {
fn.call(this, 'This is a test');
}
doSomething应该像这样使用:
doSomething( function( text ) {
console.log( text );
});
我的问题是: 在JSDoc中有官方方式来记录fn参数吗? 可能是这样的:
/**
* doSomething description
* @param {function} fn - A function that accepts an argument.
* @param {string} fn( name ) - A text passed to the fn function.
*/
function doSomething( fn ) {
fn.call(this, 'test');
}
答案 0 :(得分:2)
正如@SergiuParaschiv在评论中提到的,唯一的方法是使用@callback标签,如下所示:
Javascript代码:
/**
* A function to be passed as an argument.
* @callback doSomethingCallback
* @param {string} text - A simple text.
*/
/**
* doSomething description
* @param {doSomethingCallback} fn - A function that accepts an argument.
*/
function doSomething( fn ) {
fn.call(this, 'This is a test');
}
JSDoc结果: