简体   繁体   English

JSDoc - 稍后定义的 object 属性的文档

[英]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?如何记录 object 属性/方法,当此属性/方法稍后添加到 object,在 object 已初始化后?

Example:例子:

Let's say that I declare the following object.假设我声明了以下 object。 Documentation of ID and name work fine: IDname的文档工作正常:

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):后来,我决定添加一个属性(假设在另一个 js 文件中):

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

In that case, App.role 's documentation does not work.在这种情况下, App.role的文档不起作用。 At least, VSCode does not open the tooltip to inform me about its description.至少,VSCode 不会打开工具提示来通知我它的描述。

What I do now, is declare an empty property inside the object: role:null, and also write its documentation.我现在要做的是在 object: role:null,并编写它的文档。 This workaround works OK.此解决方法工作正常。

To make it work the object definition should be a bit different.为了使它工作,object 的定义应该有点不同。 Something like the following:类似于以下内容:

a.js一个.js

const AppUser = {}

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

b.js b.js

AppUser.role = 'admin'

c.js c.js

截屏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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