gregs

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:

JavaScript:
  1. /*@cc_on @*/
  2. /*@if (@_jscript_version>= 4)
  3. alert("JScript version 4 or better");
  4. @else @*/
  5. alert("You need a more recent script engine.");
  6. /*@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?


Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!