/* http://dean.edwards.name/my/cssQuery/src/cssQuery-standard.js */ isMSIE = eval( "false;/*@cc_on@if(@\x5fwin32)isMSIE=true@end@*/" );
eval() if you can avoid it at all.
Next. This “magical” code in a string, gives the value
false,to the variable isMSIE. Then this code uses Microsoft feature called “JScript conditional comments”1, which I have nothing against.This feature, allows for code that gets evaluated only if code is executed inside the IE. The whole “magic” above, is wrapped inside this :
A basic JScript feature to conditionally wrap the code to be executed only if JScript2 is parsing this code. But.
Inside the string the code also (for some unknown reason) checks the value of the “conditional compilation constant” ‘@_win32’ which is ‘true’ if code executes on win32 platform. Also above we have this funny ‘@\x5fwin32’ “thing”. Which seems like an unnecessary hack? Maybe it is used to allow this string, to be properly evaluated by the
eval() function ? I do not know.
What a lot of densely compressed magic, one might think ? Well … I beg to disagree.
Code needs to be maintainable. Higher the level of obfuscation is, the lower the level of maintainability is. I think this is a prime example of an obfuscated code which can be made much simpler and easy , or easier, to understand by others. This is my simple version :
/* The following line is parsed inside each and every browser, including IE */ var isMSIE = false ; /* the following line is parsed only when code is inside IE browser. On any platform. */ /*@cc_on isMSIE = true ; @*/
This solution works and does what it is supposed to do. And it is almost hilariously simple. Make it true first , and second, if in IE switch it to false.
There is no reason to additionally check the value of @win32. As simple as that. This solution works, it is simple and it is easy to understand. And the simplicity is a quality which is very important. It leads to a robust code which is easy to maintain.
Maintenance of code always happens by “significant others”. Complicated and obfuscated code is very often removed, if someone has to maintain your brilliance long after you have left the project. Never forget that.
If you want your code to survive the test of time, keep it simple. Working right, and working well.