- 论坛徽章:
- 0
|
http://www.seo-space.net/blog/41 ... al-Compilation.html
在js的注释中是可以有流程控制,这个也是在今天才发现。虽然这个东西用处不大,但是挺好玩的。
- /*@cc_on
- @if (@_win32)
- document.write("OS is 32-bit. Browser is IE.");
- @else
- document.write("OS is NOT 32-bit. Browser is IE.");
- @end
- @*/
复制代码
上面的代码就是注释中的流程控制,用@cc_on来开头就可以了,在里面就可以写if...else...end了
if语句有以下四个:
@if
@elif
@else
@end
Variables有:
@_win32 如果是win32就返回真,否则返回NaN.
@_win16 如果是win16就返回真,否则返回NaN.
@_mac 如果是apple就返回真,否则返回NaN.
@_alpha 如果运行在“DEC Alpha processo”上就返回真,否则返回NaN.
@_x86 如果是x86就返回真,否则返回NaN.
@_mc680x0 如果是Motorola 680x0 cpu就返回真,否则返回NaN.
@_PowerPC 如果是PowerPC cpu就返回真,否则返回NaN.
@_jscript 总是返回真
@_jscript_build The build number of the JScript scripting engine.
@_jscript_version 以x.x型式返回本号
IE4 supports JScript 3.x
IE5.x supports JScript 5.5 or less
IE6 supports JScript 5.6
The version number reported for JScript .NET is 7.x.
@_debug Returns true if compiled in debug mode, otherwise false.
@_fast Returns true if compiled in fast mode, otherwise false.
如果你想自己defined Variables可以使用@set
请看defined Variables例子:
@set @myvar1 = 35
@set @myvar3 = @_jscript_version
运算符:
! ~
* / %
+ -
<< >> >>>
< <= > >=
== != === !==
& ^ |
&& |
下面为try catch的例子:
- function HttpRequest(url, parameters){
- var pageRequest = false //variable to hold ajax object
- /*@cc_on
- @if (@_jscript_version >= 5)
- try {
- pageRequest = new ActiveXObject("Msxml2.XMLHTTP")
- }
- catch (e){
- try {
- pageRequest = new ActiveXObject("Microsoft.XMLHTTP")
- }
- catch (e2){
- pageRequest = false
- }
- }
- @end
- @*/
- if (!pageRequest && typeof XMLHttpRequest != 'undefined')
- pageRequest = new XMLHttpRequest()
- }
复制代码 |
|