javascript – 评论回调函数

前端之家收集整理的这篇文章主要介绍了javascript – 评论回调函数前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
只是好奇什么是评论将哪些参数传递给回调函数的好方法.

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

  1. /**
  2. * an utterly useless function
  3. *
  4. * @param {String} an useless string
  5. * @param {Boolean} an useless boolean
  6. * @param {Function} ???
  7. */
  8.  
  9. function Useless (str,bool,callback) {
  10. callback(str,bool);
  11. }

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

解决方法

通常,您只需使用发言名称编写函数调用
  1. /*
  2. * @param {String} input: the text
  3. * @param {Function} callback(output,hasChanged): called after calculation
  4. */

或者,如果参数需要说明,您可以使用多行描述:

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

猜你在找的JavaScript相关文章