Home >Web Front-end >JS Tutorial >Conditional compilation of JScript_javascript skills

Conditional compilation of JScript_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:13:061208browse

Microsoft's explanation of conditional compilation is:
Some typical uses of conditional compilation include using new features in Jscript, embedding debugging support in scripts, and tracking the execution of code.

First look at a piece of code to understand briefly:


var s=0//@cc_on 1
alert(s)


If If you are using IE, you can see that the value of s prompted by the browser is "1";

var s=0//@cc_on 1
is equivalent to:
var s=0 1

Conditional compilation provides a way to run code in comments.

Generally, we rarely use conditional compilation when writing JavaScript code. However, due to its own characteristics, conditional compilation provides convenience for our detection system and automatic identification of browser programming.
There is a very classic code:
var isMSIE = /*@cc_on!@*/false;

It can also be like this:
var IE=0//@cc_on 1

More complicated:

var IEVersion=/*@cc_on function(){ switch(@_jscript_version){ case 1.0:return 3; case 3.0:return 4; case 5.0:return 5; case 5.1:return 5; case 5.5:return 5.5; case 5.6:return 6; case 5.7:return 7; }}()||@*/0;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn