用于命名变量和函数的单个字母
上下文
我阅读了 Google 编写的 JavaScript 代码示例。它使用:
- 单个小写字母用于命名变量
- 单个大写字母用于命名函数
因此代码难以辨认。
问题
- 为什么这样命名?
- 使用什么工具来执行此操作?
Context
I read a JavaScript code example written by Google. It used:
- Single lowercase letters for naming variables
- Single uppercase letters for naming functions
So the code was illegible.
Questions
- Why this naming?
- What tools are using to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
通常,当大型 Javascript 库投入生产时,代码会被“最小化”,以便...
我认为主要动机是#1。
此过程通常涉及删除注释和空格以及更改对单个字符的变量引用等操作。
例如,查看 JSMin。
Often when large Javascript libraries are put into production the code is "minimized" in order to...
I think the primary motivator is #1 however.
This process generally involves things like removing comments and whitespace and changing variable references to single characters.
For instance, take a look at JSMin.
更少的字母意味着更少的字节意味着更快的下载,这是谷歌(声明)的主要关注点。
他们可能使用Closure Compiler,但是YUI 压缩机 仍然很受欢迎。
Fewer letters means fewer bytes means faster downloads, which is Google's (stated) primary concern.
They probably use Closure Compiler but YUI Compressor is still popular.
这就是 JavaScript 混淆!
That's JavaScript Obfuscation!
有些人这样做是为了混淆,但许多人这样做是为了缩小,因为字符越少意味着传输的文件越小。
您可以使用缩小/压缩工具,谷歌甚至有一个开源工具:
http://code.google .com/closure/compiler/
Some people do this to obfuscate, but many do it to minify because the fewer characters means that it is a smaller file to transmit.
You can use minification/compression tools and google even has one that is open source:
http://code.google.com/closure/compiler/
它有两个主要目的
http://blogscoped.com/archive/2008-02-08-n74.html
It serves two main purposes
http://blogoscoped.com/archive/2008-02-08-n74.html