簡體   English   中英

繼承 JSDoc 中的文檔

[英]Inheriting documentation in JSDoc

我正在嘗試為我的 JS 項目編寫文檔,並且我的代碼是面向對象的。 這是一個示例代碼:

/**
 * @classdesc Represents a Layer.
 * @class
 * @param {object} satellite - The satellite object.
 * @param {string} date - The image date.
 * 
 * @property {Satellite} satellite - The associated satellite.
 * 
 */
function Layer(satellite, date){

    var self = this;
    self.satellite = satellite;

    /**
     * Compute the water index from RGB imagery.
     * @function compute_wi
     * @memberOf Layer
     * @instance
     * @param {ee.ImageCollection} rgb - RGB imagery.
    */
    self.compute_wi = function(rgb){
        var image = rgb.median();
        return image.normalizedDifference(self.satellite.ndwi_bands);
    };
}


/**
 * @classdesc Class representing a Layer for SAR satellites.
 * @class
 * @augments Layer
 */
function SarLayer(satellite, date, img_layernumber, pre_post){
    Layer.call(this, satellite, date, img_layernumber, pre_post);
    var self = this;
    /**
     * Do nothing (not used for SAR imagery).
     * @function compute_wi
     * @memberOf SarLayer
     * @override
     * @instance
     * @param {ee.ImageCollection} rgb - RGB imagery.
     * @returns {ee.ImageCollection} RGB imagery
    */
    self.compute_wi = function(rgb){
        return rgb;
    };

}
SarLayer.prototype = Object.create(Layer.prototype);
SarLayer.prototype.constructor = SarLayer;

我有兩個問題:

  1. 屬性(此處為衛星成員)未在子 class 文檔中繼承,如果不簡單地復制粘貼@property...行,我如何才能做到這一點?
  2. 對於父 class 和子 class 的大部分 compute_wi 文檔是相同的。我如何繼承父 class 文檔? 如果我刪除子 class 文檔,它將繼承父 class 文檔,但不會指示該方法在子 class 中被覆蓋。我試過@inheritdoc \ @override但它不起作用。 你有什么想法?

我使用以下方法解決了我的問題:

/**
 1. @classdesc Represents a Layer.
 2. @class
 3. @param {object} satellite - The satellite object.
 4. @param {string} date - The image date.
 5. 
 */
function Layer(satellite, date){

    var self = this;

    /** Satellite object */
    this.satellite = satellite;

    /**
     * Compute the water index from RGB imagery.
     * @param {ee.ImageCollection} rgb - RGB imagery.
    */
    this.compute_wi = function(rgb){
        var image = rgb.median();
        return image.normalizedDifference(self.satellite.ndwi_bands);
    };
}

/**
 * @classdesc Class representing a Layer for SAR satellites.
 * @class
 * @augments Layer
 */
function SarLayer(satellite, date, img_layernumber, pre_post){
    Layer.call(this, satellite, date, img_layernumber, pre_post);
    var self = this;

    /** Do nothing (not used for SAR imagery). */
    this.compute_wi = function(rgb){
        return rgb;
    };

}
SarLayer.prototype = Object.create(Layer.prototype);
SarLayer.prototype.constructor = SarLayer;

所以基本上是為了:

  1. 通過刪除屬性,並在我的成員面前添加文檔。 (我也不得不用this代替self )。
  2. 我只保留paramreturns行並刪除 rest,從self更改為this使其直接工作。 它會自行檢測覆蓋。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM