【发布时间】:2015-10-23 16:07:43
【问题描述】:
我有一个函数,它接受类似字典的对象,并且必须提取一个特定属性并遍历可能的嵌套子对象:
function process(obj){
//extract ID
let secret = obj.secret;
delete obj.secret; // yes, I have to delete that property, not just set to null
// do some stuff
if (Array.isArray(obj.others)) {
// Extract others
let others = obj.others;
delete obj.others; // yes, I have to delete that property too
// Process children too
others.forEach(foo);
}
}
我使用这个函数来处理对象:
class MyClass {
contructor() {
//init
}
getDictionary() {
return {
secret: 123,
baz: 'baz',
bar: 'bar',
others: [{
secret: OtherClass,
forbar: 'foobar',
others: [{...},...]
},{
...
}]
};
}
parse() {
return process(this.getDictionary());
}
}
Closure Compiler 总是将 process 函数中的“obj.secret”重命名为(类似于)“aa”,但并不总是将 getDictionary 返回的对象中的“secret”属性重命名时间>。如果是这样,他们没有以相同的方式重命名“秘密”属性。
我不想导出那些 - obj['secret'] :我希望它们被重命名。我在 Closure Compiler guide 中寻找 JSDoc 注释,但我不知道该怎么做。
特别是如何定义字典,它具有强制性的“秘密”属性(类型:数字或某个类)、可选的“其他”属性(相同结构的字典数组)和零个或多个字符串属性。
【问题讨论】:
标签: google-closure-compiler jsdoc