Look at this piece for code in ArcGIS 3.0 for javascript. https://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.0
Inside there is "if(0)" and "if(1)", why is there a need for this? Isn't if(0) always false and if(1) always true?
The Dojo build tools are what does that (under given build options), but not for obfuscation. If you look at non-built dojo.js and corresponding built dojo.js.uncompressed.js files, you can see that the build tool is replacing has("somefeature") calls with hardwired true/false tests. As noticed, this can and does create unreachable code. Why do this? Because then a smart optimizing compiler (e.g. Google Closure) can prune all that dead code out, resulting in a smaller file (sometimes MUCH smaller...that's the point).
Conceptually, it goes something like this:
Check out current "Dojo Build System" documentation and http://jamesthom.as/blog/2012/08/03/finding-nano/ for more info. Also, here's a good low/code-level description of this process.
P.S. "if(0)/if(1)" isn't really obfuscation...kinda the opposite. If someone wanted to confuse, they'd more likely have "if(a)...if(b)...if(c)..." with vars set far, far away. However, minifiers produce more obfuscated code than that on their own. Check out dojo.js source before and after it's been run through Closure; the end product bears little resemblance to original.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With