我想为添加为Object.defineProperty
. 我想这样的事情可能会奏效:
/** @constructor */
function MyClass() {
/** @property {Number} rnd */
Object.defineProperty(this, 'rnd', {
get : function () { return Math.random(); }
});
}
但是生成的 JSDoc 解释没有这个属性:
$ jsdoc -X test.js
[
{
"comment": "/** @constructor */",
"meta": {
"range": [ 20, 167 ],
"filename": "test.js",
"lineno": 2,
"path": "/jsdoctest",
"code": {
"id": "astnode100000001",
"name": "MyClass",
"type": "FunctionDeclaration",
"paramnames": []
},
"vars": { "": null }
},
"kind": "class",
"name": "MyClass",
"longname": "MyClass",
"scope": "global"
},
{
"comment": "",
"meta": {
"range": [ 116, 159 ],
"filename": "test.js",
"lineno": 5,
"path": "/jsdoctest",
"code": {
"id": "astnode100000012",
"name": "get",
"type": "FunctionExpression",
"value": "function"
}
},
"undocumented": true,
"name": "get",
"longname": "get",
"kind": "function",
"scope": "global"
},
{
"kind": "package",
"longname": "package:undefined",
"files": [ "/jsdoctest/test.js" ]
}
]
记录此类属性的最合适方法是什么?(可能是插件?)