我有这样的结构:
// this is an object I instantiate elsewhere like var l=new Layer()
function Layer() {
// exported members
this.function1=function() {....}
.
.
.
this.function1000=function() {....}
.
.
// private property
var keepPropertyNames={
keepMe1:4,
keepMe2:2,
keepMe3: {
keepMe31:4,
keepMe32:4,
keepMe33:4,
}
}
}
如何判断闭包编译器-advanced模式 - 重命名所有内容,包括Layer类及其导出的成员,但不是内部keepPropertyNames对象中的属性?我该如何宣布外部人员?
提前完成。
答案 0 :(得分:0)
不要混淆外部和出口。
处理此问题的最简单方法是引用属性名称:
// private property
var keepPropertyNames={
"keepMe1":4,
"keepMe2":2,
"keepMe3": {
"keepMe31":4,
"keepMe32":4,
"keepMe33":4,
}
}
Closure编译器不会重命名引用的属性。
声明具有所有可能类型的外部接口。这可以作为记录类型完成:
实习医生
/** @typedef {{
* keepMe1: number,
* keepMe2: string,
* keepMe3: Object.<string, number>
* }}
*/
var KeepPropertyNamesRecord;
来源
/** @type {KeepPropertyNamesRecord} */
var keepPropertyNames={
keepMe1:4,
keepMe2:2,
keepMe3: {
"keepMe31":4,
"keepMe32":4,
"keepMe33":4,
}
}
您还必须为子对象声明类型,例如keepMe3
。