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

Conditional compilation of JScript_javascript skills

WBOY
Release: 2016-05-16 19:13:06
Original
1209 people have browsed it

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;

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template