我有一个重载的切换函数,想用 JSDoc 记录这些行为。
如果该值已定义,则窗口状态将设置为 truthy 参数的 bool 值,如果未定义,则窗口状态会切换。我正在寻找这样的东西。
/**
* 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 });
}
最佳答案
取自here :
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) { // ... }
但是请注意,构造函数重载不会组合在一起。每个重载仍然接收完整的成员列表,这样部分文档就变得多余了。但是,可能可以在模板中修复。
关于javascript - JSDoc 中的文档重载函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49523358/