Cry*_*ird 5 javascript jsdoc jsdoc3
假设你有这个功能:
/**
* doSomething description
* @param {function} fn - A function that accepts an argument.
*/
function doSomething( fn ) {
fn.call(this, 'This is a test');
}
Run Code Online (Sandbox Code Playgroud)
doSomething应该像这样使用:
doSomething( function( text ) {
console.log( text );
});
Run Code Online (Sandbox Code Playgroud)
我的问题是: 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');
}
Run Code Online (Sandbox Code Playgroud)
正如 @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');
}
Run Code Online (Sandbox Code Playgroud)
JSDoc 结果:
| 归档时间: |
|
| 查看次数: |
116 次 |
| 最近记录: |