Conditional compilation
by gregs on Aug.23, 2005, under JavaScript, browser
What with the buzz going on around xmlHttpRequest, I decided to have a little play with the technology (yes I know very me too of me). One tutorial/example site I stumbled across "Guide to Using XMLHttpRequest (with Baby Steps)" used some interesting JavaScript: Conditional Compilation. Here is an example:
-
/*@cc_on @*/
-
/*@if (@_jscript_version>= 4)
-
alert("JScript version 4 or better");
-
@else @*/
-
alert("You need a more recent script engine.");
-
/*@end @*/
From the looks of it, it's an IE only thing, but I wonder what the advantages are of using this code over a regular browser check? Is this a more reliable way than using window.ActiveXObject and, if you are specifically playing around with xmlHttpRequest, based on that condition making the correct create object call?