Conditional compilation _javascript techniques for JScript
Source: Internet
Author: User
Microsoft's interpretation of conditional compilation is:
Some typical uses of conditional compilation include using new features in Jscript, embedding debugging support in scripts, and tracking code running.
First look at a piece of code simple to understand:
var s=0//@cc_on +1
Alert (s)
If you are using IE you can see that the browser pop-up tip s is the value of "1";
var s=0//@cc_on +1
In IE is equivalent to:
var s=0+1
Conditional compilation provides a way to run code in a comment.
In general, we rarely use conditional compilation when writing JavaScript code. However, conditional compilation because of its own characteristics, for our detection system, automatic recognition of browser programming is convenient.
There's a classic piece of code:
var Ismsie =/* @cc_on!@*/false;
You can also do this:
var ie=0//@cc_on +1
A bit 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; CAs e 5.1:return 5; Case 5.5:return 5.5; Case 5.6:return 6; Case 5.7:return 7; }}()|| @*/0;
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.