const objectname = {
property: 0,
set (value) {
this.property = value;
}
}
How would you document these example lines with JSDoc comments?
This is what I already tried but it doesn’t show objectName.set as a method and doesn’t show its parameters.
/**
* Represents an object with a property and a set method.
* @typedef {object} ObjectName
* @property {number} property - The numeric property of the object.
* @property {Function} set - Sets the property value to the specified value.
* @param {number} value - The value to set the property to.
* @returns {void}
*/
/**
* An instance of ObjectName.
* @type {ObjectName}
*/
const objectName = {
property: 0,
/**
* Sets the property value to the specified value.
* @param {number} value - The value to set the property to.
* @returns {void}
*/
set(value) {
this.property = value;
}
};
>Solution :
I’m not a JSDoc expert, and maybe I’m being too simplistic, but this seems to work:
/**
* An object that blah blah blah...
*/
const objectname = {
/**
* The numeric property of the object.
* @type number
*/
property: 0,
/**
* Sets the `property` to the given value.
* @param {number} value - The value to set the property to.
* @returns {void}
*/
set(value) {
this.property = value;
},
};
When I use that in VS Code, I get the type and description of things (including the parameter type on set) in popups and such.