javascript - 评论回调函数

标签 javascript coding-style documentation comments

只是好奇什么是注释将传递给回调函数的参数的好方法。

假设我们有以下代码和不完整注释

/**
 * an utterly useless function
 *
 * @param {String} an useless string
 * @param {Boolean} an useless boolean
 * @param {Function} ???
 */

function Useless (str, bool, callback) {
  callback(str, bool);
}

用 str 和 bool 作为参数调用回调有什么好方法?

最佳答案

通常你只会写一个函数的调用,并说出名字:

/* 
 * @param {String} input: the text
 * @param {Function} callback(output, hasChanged): called after calculation
 */

或者,如果参数需要解释,你可以使用多行描述:

/* 
 * @param {String} input: the text
 * @param {Function} callback(result, change)
 *         the function that is called after calculation
 *         result {String}: the output of the computation
 *         change {Boolean}: whether a change has occurred
 */

关于javascript - 评论回调函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11787678/

相关文章:

python - opencv python 文档

javascript - R Shiny 仪表板 valueBox : Animation from one number to another

javascript - 内容脚本未在另一个扩展页面的 iframe 中运行

javascript - 使用 Jquery 的空间场

c - 使用全局变量最优雅的方法是什么?

php/html编码风格

java - 使用输出参数是否被认为是不好的做法?

c++ - 在代码中管理大量文本(并支持翻译)的最佳方式是什么?

android - 在 Android 应用程序的项目树中的什么地方放置开发人员的文档?

javascript - C#序列化为JS对象而不引用一些值