如何使用JSDoc记录函数返回的函数 [英] How to document a function returned by a function using JSDoc

查看:115
本文介绍了如何使用JSDoc记录函数返回的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用JSDoc作为参数文档。

I am using JSDoc for parameter documentation.

很清楚如何记录 many_prompts的参数类型 ,但是记录它返回的函数的正确方法是什么?

It is clear how to document the parameter types for many_prompts, but what is the right way to document the function it returns?

/**
 * @param {Number} - number of times to prompt
 * @return {Function(prompt{Number})} - the returned function
 */
function many_prompts(count) {
  return function(prompt) {
    for(var i=0; i < count; i++) alert(prompt);
  }
}


//Example of use:
var y  =many_prompts(3);
y('Hello World');


推荐答案

您可以记录内部函数,然后将其引用为所以

You can document the inner function and then reference it like so

/**
 * @param {Number} - number of times to prompt
 * @return {many_prompts~inner} - the returned function
 */
function many_prompts(count){
  /**
   * My inner function
   *
   * @param {object} prompt Some parameter
   */
  var inner = function(prompt){
    for(var i=0;i<count;i++) alert(prompt}
  };
  return inner;
}

这篇关于如何使用JSDoc记录函数返回的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆