如何在类构造函数中记录对象



我目前正在使用JSDoc尝试记录以下代码。。。

class Test {
/**
* @param {Object} raw The raw data.
*/
constructor(raw) {
/**
* Used for things and stuff. It can be useful when referencing Test.myObject.myValue.
* @type {Object}
*/
this.myObject = {
/**
* This is my string... It does things. Very useful.
* @type {String}
*/
myValue: raw.thisIsMyValue
}
}
}

但我不完全确定如何做到这一点。上面的例子在VSCode中有效,但在生成文档时无效。我尝试过一个typedef,但没有成功,因为它使它成为全局typedef而不是测试类原型的一部分。我该怎么做?

我知道如何使用@param为函数定义"匿名"对象,但我不知道如何为类原型定义。我已经在谷歌上搜索了一个半小时了,但没有运气。

我发现了

  1. 我的调试方法没有帮助,因为我用于文档生成器的主题隐藏了属性
  2. 在创建typedef时,您可以在对象前面去掉类型,然后它将其列为属性

示例

class Test {
/**
* @param {Object} raw The raw data.
*/
constructor(raw) {
/**
* Used for things and stuff. It can be useful when referencing Test.myObject.myValue.
* @typedef MyObject
* @property {String} myValue This is my string... It does things. Very useful.
*/
this.myObject = {
myValue: raw.thisIsMyValue
}
}
}

最新更新