javascript - 谷歌闭包编译器不重命名属性

标签 javascript google-closure-compiler

我有一个从 JSON.parse 生成的对象数组。我像这样访问它的属性:

AnObject['PhoneList'][i]['PhoneLabel']

当我通过 google 闭包编译器运行代码时,属性的名称没有被混淆并且清晰可见。为什么不混淆对象属性的名称?

最佳答案

Google 闭包很难确定它可以重命名什么,不能重命名什么。例如,任何由 Google 闭包编译代码之外的代码创建或引用的数据结构都不能重命名,否则双方将不会期望相同的代码。此外,通过构造的字符串引用属性使得闭包几乎不可能很好地完成它的工作。因此,Closure 有一大堆规则和设置来帮助你控制它并指导它做什么。我建议您阅读这些引用资料中的这些规则/设置:

https://developers.google.com/closure/compiler/docs/api-tutorial3

https://developers.google.com/closure/compiler/docs/compilation_levels

https://groups.google.com/group/closure-stylesheets-discuss/browse_thread/thread/386ba6db27a43887?pli=1

https://developers.google.com/closure/compiler/docs/limitations

并且,引用自最后的引用资料:

String representations of function or parameter names:

The Compiler renames functions and function parameters but does not change any strings in your code that refer to functions or parameters by name. You should thus avoid representing function or parameter names as strings in your code. For example, the Prototype library function argumentNames() uses Function.toString() to retrieve the names of a function's parameters. But while argumentNames() might tempt you to use the names of arguments in your code, Simple mode compilation breaks this kind of reference.

关于javascript - 谷歌闭包编译器不重命名属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9610365/

相关文章:

javascript - 添加所选商品的总价(Javascript)

javascript - 如何将 wro4j 与 Closure 库和编译器一起使用?

javascript - Google 关闭外部依赖项

javascript - 异步等待未按预期工作。使用 await 后值为 'undefined'

javascript - 滚动到 DOM 中元素的顶部 - Angular 8

javascript - 恶意javascript注入(inject)登录页面

javascript - gif 加载后更改背景图像?

javascript - 在编译的 javascript 中触发回调

javascript - 为什么 Google Closure Compiler 在扩展 Date() 的 ES6 对象上失败?

javascript - 关于将闭包编译器集成到构建流程的建议