您的位置:首页 > 运维架构 > 反向代理

CentOS 6.5下Squid代理服务器的安装与配置

2015-08-12 11:41 507 查看
switch 语句



[b] switch(typeof x) {
      case 'number':            // Convert the number to a hexadecimal integer
        return x.toString(16);
      case 'string':            // Return the string enclosed in quotes
        return '"' + x + '"';
      case 'boolean':           // Convert to TRUE or FALSE, in uppercase
        return x.toString( ).toUpperCase( );
      default:                  // Convert any other type in the usual way
        return x.toString( )
    }
case 关键字后跟随的一般是 数字和字符串常量,也可以跟表达式,但是会产生不可思议的副作用,所以不提倡用expression。

 

[b]for/in 语句




语法如下:

for (variable in object)
    statement

variable should be either the name of a variable(应该是一个变量名), a var statement declaring a variable, an element of an array, or a property of an object 。

object is the name of an object or an expression that evaluates to an object 。

The for/in statement provides a way to loop through the properties of an object. The body of the for/in loop is executed once for each property of object. Before the body of the loop is executed, the name of one of the object's properties is assigned to variable, as a string. Within the body of the loop, you can use this variable to look up the value of the object's property with the [] operator

for (var prop in my_object) {
    document.write("name: " + prop + "; value: " + my_object[prop], "<br>");
}

 

Note that the variable in the for/in loop may be an arbitrary expression, as long as it evaluates to something suitable for the left side of an assignment. This expression is evaluated each time through the loop, which means that it may evaluate differently each time. For example, you can use code like the following to copy the names of all object properties into an array:(通过下面的代码,把一个对象的所有属性名复制到一个数组中)
 
var o = {x:1, y:2, z:3};
var a = new Array( );
var i = 0;
for(a[i++] in o) /* empty loop body */;
 

注意 对象引用属性的方法 既可以通过 o.x,也可以通过这种方式:o["x"]

 
[b]break 语句

 
break 语句会使程序立即跳出最内层的循环或switch语句,语法为 break;
break 后还可以跟一个标签名: break labelname;
对break 语句中的标签中的唯一限制就是他命名的是一个封闭的语句。
 

outerloop:
  for(var i = 0; i < 10; i++) {
    innerloop:
      for(var j = 0; j < 10; j++) {
          if (j > 3) break;             // Quit the innermost loop
          if (i == 2) break innerloop;  // Do the same thing
          if (i == 4) break outerloop;  // Quit the outer loop
          document.write("i = " + i + " j = " + j + "<br>");
      }
  }
  document.write("FINAL i = " + i + " j = " + j + "<br>");

 

或者:

 test:{

       var a = 2 ;

        ...

        if(a =5){

           break test;

     }

}

 

[b]

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: