Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

jsdoc should be before class or constructor in javascript?

Im using a vscode (but should be the same in any code editor), and in the following code, when I hover over Circle, it shows me the contents of the jsdoc i’ve written, but doesn’t show them when i hover the variable radius. What should I do? Is the only way is to write the jsdoc just above the constructor, ’cause that worked in the past?

/**
 * This class represents a circle and can calculate its perimeter and area
 * https://en.wikipedia.org/wiki/Circle
 * @constructor
 * @param {number} radius - The radius of the circle.
 */
export default class Circle {
  contructor(radius) {
    this.radius = radius
  }

  perimeter = () => {
    return this.radius * 2 * Math.PI
  }

  area = () => {
    return Math.pow(this.radius, 2) * Math.PI
  }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Is the only way is to write the jsdoc just above the constructor, ’cause that worked in the past?

Yes.

The documentation for classes shows that the description of the arguments passed to the constructor are specified in documentation on the constructor, not the class.

/** Class representing a point. */
class Point {
    /**
     * Create a point.
     * @param {number} x - The x value.
     * @param {number} y - The y value.
     */
    constructor(x, y) {
        // ...
    }

It also states:

You don’t need to use tags such as @class and @constructor with ES 2015 classes—JSDoc automatically identifies classes and their constructors simply by parsing your code.

@constructor is for use when writing traditional constructor functions without the class keyword.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading