I was hoping that my code, something like below, could generate documents describing each property of the object literal with JSDoc(v2.4.0), but it did not work. Does anyone know how to work with JSDoc to generate documents from code that uses getter/setter?
/** Enum of days of week. */
var Day = {
/** Sunday. */
get Sun() { return 0; },
/** Monday. */
get Mon() { return 1; },
/** Thuesday. */
get Tue() { return 2; },
/** Wednesday. */
get Wed() { return 3; },
/** Thursday. */
get Thu() { return 4; },
/** Friday. */
get Fri() { return 5; },
/** Saturday. */
get Sat() { return 6; }
}
JavaScript Accessors (Getters and Setters)ECMAScript 5 (ES5 2009) introduced Getter and Setters. Getters and setters allow you to define Object Accessors (Computed Properties).
Getters and setters allow us to define Object Accessors. The difference between them is that the former is used to get the property from the object whereas the latter is used to set a property in an object.
The getter and setter method gives you centralized control of how a certain field is initialized and provided to the client, which makes it much easier to verify and debug. To see which thread is accessing and what values are going out, you can easily place breakpoints or a print statement.
@property is used to get the value of a private attribute without using any getter methods. We have to put a line @property in front of the method where we return the private variable. To set the value of the private variable, we use @method_name.
Use @type
to document JavaScript get
and set
accessors. Something like the following should work with JSDoc:
/**
* Sunday.
* @type {number}
*/
get "Sun"() { return 0; },
/**
* Monday.
* @type {number}
*/
get "Mon"() { return 1; },
This documents each property as a member with a type of number
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With