|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Conditional Compilation Statements
The following statements enable JScript to control the compilation of a script depending on the values of the conditional compilation variables. You can use the variables provided by JScript, or you can define your own with the @set directive or the /define command-line option.
|@cc_on||Activates conditional compilation support.|
|@if||Conditionally executes a group of statements, depending on the value of an expression.|
|@set||Creates variables used with conditional compilation statements.|
The @cc_on, @if, or @set statements activate conditional compilation. Some typical uses for conditional compilation include using new features in JScript, embedding debugging support into a script, and tracing code execution.
When writing scripts to be run by Web browsers, always place conditional compilation code in comments. Consequently, hosts that do not support conditional compilation can ignore it. Here is an example.
/*@cc_on @*/ /*@if (@_jscript_version >= 5) document.write("JScript Version 5.0 or better.<BR>"); @else @*/ document.write("You need a more recent script engine.<BR>"); /*@end @*/
This example uses special comment delimiters that are only used if the @cc_on statement has activated conditional compilation. Scripting engines that do not support conditional compilation display a message advising of the need for a new scripting engine without generating errors. Engines that support conditional compilation compile either the first or second
document.write, depending on the version of the engine. Note that version 7.x represents JScript .NET. For more information, see Detecting Browser Capabilities.
Conditional compilation is also useful for server-side scripts and command-line programs. In those applications, conditional compilation can be used to compile additional functions into a program to help with profiling when in debug mode.