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.
Statements
Statement |
Description |
---|---|
Activates conditional compilation support. |
|
Conditionally executes a group of statements, depending on the value of an expression. |
|
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.
See Also
Concepts
Conditional Compilation Variables
Conditional Compilation Directives
Detecting Browser Capabilities