【问题标题】:Is it possible to specify function overrides in JSDoc?是否可以在 JSDoc 中指定函数覆盖?
【发布时间】:2017-02-23 02:40:25
【问题描述】:

我要记录的一个示例如下:

/**
 * @return {boolean}
 */
Contains(rectangle_or_x, y, tolerance) {
    if (rectangle_or_x instanceof Rectangle) { return ((rectangle_or_x.X >= this._x) && (rectangle_or_x.Y >= this._y) && (rectangle_or_x.Right <= this._right) && (rectangle_or_x.Bottom <= this._bottom)); }
    if ((tolerance === undefined) || (tolerance === null) || (!Rectangle._isNumeric(tolerance))) {
        if ((rectangle_or_x < this._x) || (y < this._y) || (rectangle_or_x > this._right) || (y > this._bottom)) { return (false); }
    } else if (((rectangle_or_x + tolerance) < this._x) || ((y + tolerance) < this._y) || ((rectangle_or_x - tolerance) > this._right) || ((y - tolerance) > this._bottom)) { return (false); }
    return (true);
}

其中有 3 个可能的调用,其中一个可以忽略,因为它基于可选的 tolerance 参数,但基数两个以排他方式重叠:

Contains(Rectangle rectangle_or_x)
Contains(Number rectangle_or_x, Number y[, Number tolerance])

鉴于不同的类型(我知道 JavaScript 是无类型的,但就示例而言,涉及到确定的类型)是否可以使用 JSDoc 创建单独的 @param 值集(主要用于 WebStorm 中的智能感知,但理论上也适用于后续文档。)

【问题讨论】:

    标签: webstorm jsdoc


    【解决方案1】:

    没有办法指定专有的 JSDocs 集。

    你可以试试这样的:

    /**
     * @param {Rectangle|Number} rectangle_or_x
     * @param {Number=} y
     * @param {Number=} tolerance
     * @return {boolean}
     */
    Contains(rectangle_or_x, y, tolerance) {}
    

    【讨论】:

      猜你喜欢
      • 2011-04-06
      • 2011-09-22
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      • 2022-11-04
      • 1970-01-01
      • 2020-01-28
      • 1970-01-01
      相关资源
      最近更新 更多