简体   繁体   中英

JSDoc - Documentation for object property that is defined later

How to document an object property/method, when this property/method gets added to the object later , after the object has been initialized?

Example:

Let's say that I declare the following object. Documentation of ID and name work fine:

let AppUser = {
   /** The user's id */
   ID: 0,
   /** The user's name */
   name: "guest",
};

Later, I decided to add a property (let's say in another js file):

/** The role of the AppUser */
App.role = "admin";

In that case, App.role 's documentation does not work. At least, VSCode does not open the tooltip to inform me about its description.

What I do now, is declare an empty property inside the object: role:null, and also write its documentation. This workaround works OK.

To make it work the object definition should be a bit different. Something like the following:

a.js

const AppUser = {}

AppUser.ID = 0
AppUser.name = 'guest'

b.js

AppUser.role = 'admin'

c.js

截屏

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM