I always wondered why js compressors don’t do this. Let’s say I have a minified script like this:
(function($){var a=$("a");1<a.length&&10>a.length?alert(a.length):alert($("p").length)})(jQuery);
Why doesn’t it compile to something like this:
(function($,L){var a=$("a");1<a[L]&&10>a[L]?alert(a[L]):alert($("p")[L])})(jQuery,'length');
Meaning changing every occurrence of a .property with a [minified key] and pass a string and arg receiver to the iife (basically what I did above with the .length)
Imagine how much more this would minify jQuery with 159 .length, 62 .each, 15 .appendChild etc. Just the .lengths alone would save over 600 bytes!
Also using the example above why does it waste space on a var keyword when you can reserve a space in that functions scope by declaring another parameter:
(function($,L,a){a=$("a");1<a[L]&&10>a[L]?alert(a[L]):alert($("p")[L])})(jQuery,'length');
Also while I have you here, why not put the entire jQuery into an eval and save on another 572 function keywords (4.5k)?
I would imagine that it doesn’t want to assume that you want the expense of a variable lookup in addition to the property lookup.
If you use Closure Compiler, it will actually undo those types of references if you do it manually.
Ultimately, if you gzip, I don’t think those obfuscations add up to much. I wouldn’t be surprised if in some cases it actually makes your gzipped version larger.