gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 18:31:03 26 4
gpt4 key购买 nike

我有一个从 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com