最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Single letters for naming variables and functions - Stack Overflow

programmeradmin2浏览0评论

Context

I read a JavaScript code example written by Google. It used:

  1. Single lowercase letters for naming variables
  2. Single uppercase letters for naming functions

So the code was illegible.

Questions

  • Why this naming?
  • What tools are using to do this?

Context

I read a JavaScript code example written by Google. It used:

  1. Single lowercase letters for naming variables
  2. Single uppercase letters for naming functions

So the code was illegible.

Questions

  • Why this naming?
  • What tools are using to do this?
Share Improve this question edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Mar 13, 2011 at 21:18 GG.GG. 21.8k14 gold badges90 silver badges132 bronze badges
Add a comment  | 

5 Answers 5

Reset to default 12

Often when large Javascript libraries are put into production the code is "minimized" in order to...

  1. Decrease the download size
  2. Make it more difficult to reverse engineer the code

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.

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.

That's JavaScript Obfuscation!

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/

It serves two main purposes

  • reduced bandwidth, since Google serves so many pages
  • obfuscation

http://blogoscoped.com/archive/2008-02-08-n74.html

发布评论

评论列表(0)

  1. 暂无评论