conditional annotations in JScript detailed _javascript tips

Source: Internet
Author: User

JScript can use the following statement to control the compilation of a script based on the value of a conditional compilation variable. You can use either the variables provided by JScript, or you can define your own variables by using the @set directive or the/define command-line option.

@cc_on
Activate conditional compilation support.

@if
Conditionally executes a set of statements based on the value of an expression.

@set
Create a variable that uses conditional compilation statements.

Activate conditional compilation @cc_on, @if, or @set statement. Some typical uses of conditional compilation include the use of new features in JScript, embedding debugging support in a script, and tracking code execution.

When you write a script that is run by a Web browser, you always place conditional compilation code in a comment. Therefore, a host that does not support conditional compilation can ignore the code. This is an example.

Copy Code code as follows:


This example uses special annotation delimiters that are used only after the @cc_on statement activates the conditional compilation. Script engines that do not support conditional compilation display a message suggesting that a new scripting engine needs to be used without an error. The engine that supports conditional compilation compiles the first or second document.write based on the version of the engine. Note that the 7.x version represents JScript. NET. For more information, see Detecting Browser capabilities.

Conditional compilation is also useful for server-side scripting and command-line programs. In these applications, conditional compilation can be used to compile other functions into a program that is easy to analyze in debug mode.


The following predefined variables are available for conditional compilation.

@_win32
True if the/platform option is not specified or the/PLATFORM:ANYCPU option is specified when running on the WIN32 system;

@_win16
True if running on the Win16 system, otherwise NaN.

@_mac
True if running on Apple Macintosh system, otherwise NaN.

@_alpha
True if running on the DEC Alpha processor, otherwise NaN.

@_x86
True if it is running on an Intel processor and the/platform option is not specified or the/PLATFORM:ANYCPU option is specified;

@_mc680x0
True if running on the Motorola 680x0 processor, otherwise NaN.

@_powerpc
True if running on the Motorola PowerPC processor, otherwise NaN.

@_jscript
is always true.

@_jscript_build
The build number of the JScript script engine.

@_jscript_version
A number that represents the JScript version number in major.minor format.

@_debug
True if compilation is in debug mode, otherwise false.

@_fast
True if compilation is in quick mode, otherwise false.

Attention
The version number of the JScript. NET report is 7.x. The version number of the JScript 8.0 report is 8.x.

Before you can use conditional compilation variables, you must first open conditional compilation. @cc_on statement to open conditional compilation. Conditional compilation variables are typically used in scripts written for Web browsers. Conditional compilation variables are rarely used in scripts written for ASP or asp.net pages or command-line programs because other methods can be used to determine compiler compatibility.

When you write a script for a Web page, you always place the conditional compilation code in a comment. This allows a host that does not support conditional compilation to ignore the code. This is an example.


Copy Code code as follows:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.