我有用 JavaScript 编写的图形构造函数。文档有点乏味。以下是我的代码和文档的一部分,但无法按我的意愿工作:
function Graph() {
....
var nodes = [];
Object.defineProperties(this, {
/**
* An array of all node handles in the graph
*
* @return {Array}
*/
nodes: {
get: function() {
var ids = [];
for (var id in nodes) {
ids.push(id);
}
return ids;
}
}
});
....
}
基本上,我要做的是确保无法使用除提供节点列表副本而不是实际节点列表所提供的方法以外的其他方式来操作图形。
这很好用,但在 JsDoc 中,它被定义为静态的:
<static> Graph.nodes
An array of all node handles in the graph
现在,这个属性不是静态的。它对于图形的所有实例都是独立的。我的猜测是 JsDoc 认识到 nodes
属性的定义在 Object.defineProperties()
中,并声称这里的所有声明都是静态的。
有没有办法告诉 JsDoc 这个属性实际上不是静态的?我只能找到标签 @static
,它的作用恰恰相反。
最佳答案
有@instance,见documentation
//编辑:工作示例
/**
* @constructor
*/
function Graph() {
var nodes = [];
Object.defineProperties(this, {
/**
* An array of all node handles in the graph
* @return {Array}
* @memberof Graph
* @instance
*/
nodes: {
get: function() {
var ids = [];
for (var id in nodes) {
ids.push(id);
}
return ids;
}
}
});
}
关于javascript - JsDoc:从属性中删除 "static"标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28764364/