JSDoc中的文档重载函数 [英] Document overloaded function in JSDoc

查看:140
本文介绍了JSDoc中的文档重载函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个重载的 toggle 函数,想用JSDoc记录行为.

I have an overloaded toggle function and want to document the behaviors w/ JSDoc.

如果定义了该值,则将窗口状态设置为truey参数的布尔值,如果未定义,则将切换窗口状态.我正在寻找这样的东西.

If the value is defined the window state is set to the boolean value of the truthy parameter, if undefined the window state toggles. I'm looking for something like this.

/**
 * Set the map window in mobile
 * @param {undefined|*} on - toggle or set the window state
 *  - {undefined} toggles window state
 *  - {*} set window state
 */
toggleWindow(on) {
  if (on === undefined) {
    on = !this.state.window;
  }
  this.setState({ mapWindow: !!on });
}

推荐答案

来自此处:

您需要像这样嵌套每个注释的开头和结尾:

You need to nestle the start and end of each comment together like so:

/**
 * DateRange class to store ranges and query dates.
 *
 * @constructor
 * @param {(Moment|Date)} start Start of interval
 * @param {(Moment|Date)} end End of interval
 *//**
 * DateRange class to store ranges and query dates.
 *
 * @constructor
 * @param {!Array} range Array containing start and end dates.
 *//**
 * DateRange class to store ranges and query dates.
 *
 * @constructor
 * @param {!String} range String formatted as an IS0 8601 time interval
 */
function DateRange(start, end) {
  // ...
}

但是,请注意,构造函数重载没有组合在一起.每个重载仍然接收完整的成员列表,因此部分文档变得多余.但是,该模板可能是可修复的.

Note, however, that constructor overloads are not grouped together. Each overload still receives the full member list, such that part of the documentation becomes redundant. Might be fixable in the template, however.

这篇关于JSDoc中的文档重载函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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