0

I am trying to document my code using JSDoc but I can't figure out how to make it work for it to recognise class inheritance. Here is a sample code:

/**
 * @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
     * @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
     * @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;

In the created JSDoc, I don't see that compute_wi in SARLayer is an overriden function from Layer. I see the attribute Satellite in the documentation of Layer but not in the one of SARLayer, how can I make it appear there? Same for the other methods that I don't override..

Here is an example of what I expected: expected

Here is what I get: actual

Is it because I declare my methods with the keyword self? Which I need to make class inheritance work (call superclass method when needed).

1 Answers1

0

You seem to lack the @instance type hint that tells the JSDoc these are instance (not static) methods.

Applying the @instance to both methods seem to yield the correct output of the documentation generator - I see an Overrides together with a link to the base class method (which is what you ask about).

Wiktor Zychla
  • 47,367
  • 6
  • 74
  • 106
  • Oh thanks, it works! Do you have any ideas on how to make the properties of Layer appear as properties of SARLayer? Also, is there a way to say that the function has been overridden without copying the whole function documentation. i.e. I would like to do ``` /** * @override */ ``` instead of ``` /** * Do nothing (not used for SAR imagery). * @function compute_wi * @memberOf SarLayer * @override * @param {ee.ImageCollection} rgb - RGB imagery. * @returns {ee.ImageCollection} RGB imagery */ ``` Cause most of the stuff is the same. – Theo Patron Nov 18 '22 at 16:53
  • Glad this helped, if it works for you please accept this answer as correct. Also, avoid asking additional questions in comments, just create a new question if you wish. Have a nice day. – Wiktor Zychla Nov 18 '22 at 18:50