如何使用JSDoc记录回调? [英] How to document callbacks using JSDoc?
本文介绍了如何使用JSDoc记录回调?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出一个以回调函数为参数的Javascript函数:
Given a Javascript function that takes callback functions as parameters:
var myFunction = function(onSuccess, onFailure) {...}
如何记录onSuccess
的返回类型和参数?
How do I document onSuccess
's return type and arguments?
推荐答案
在JSDoc 3.1和更高版本中,您可以使用新的@callback
标记在单独的注释块中描述回调函数.然后,您可以在文档中为您的方法引用回调.
In JSDoc 3.1 and later, you can use the new @callback
tag to describe the callback function in a separate comment block. You can then refer to the callback in the docs for your method.
这是一个例子:
/** @class */
function MyClass() {}
/**
* Do something.
* @param {MyClass~onSuccess} cb - Called on success.
*/
MyClass.prototype.myFunction = function(cb) {
// code
};
/**
* Callback used by myFunction.
* @callback MyClass~onSuccess
* @param {number} resultCode
* @param {string} resultMessage
*/
有关更多信息,请参见使用JSDoc .
See Use JSDoc for more information.
这篇关于如何使用JSDoc记录回调?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文