irb中<<左位移操作符问题
如果在IRB中调以下代码会出现类here document的作用,而不是直接进行位移操作,虽然结果最后还是对的。
irb(main):020:0> a = 2
irb(main):020:0> c = a <<1
irb(main):021:0" 2
irb(main):022:0" 1
=> 1
irb(main):023:0> c
=> 4
如果a <<1中1之前再加个半角空格,那会正常运算,不知是否属于IRB的Bug,在Ruby脚本中直接运行是正常的。
如果在IRB中调以下代码会出现类here document的作用,而不是直接进行位移操作,虽然结果最后还是对的。
irb(main):020:0> a = 2
irb(main):020:0> c = a <<1
irb(main):021:0" 2
irb(main):022:0" 1
=> 1
irb(main):023:0> c
=> 4
如果a <<1中1之前再加个半角空格,那会正常运算,不知是否属于IRB的Bug,在Ruby脚本中直接运行是正常的。
可以使用“ ” ”(双引号)或“ ’ ”(单引号)括住字符串,而不仅是“ ’ ”(单引号)。在字符串中使用“ \ ”作为转义字符。
能够在带有“:=”赋值操作符的语句中设置变量。
mysql> SELECT @a:=SUM(total),@b=COUNT(*),@a/@b AS avg
-> FROM test_table;
mysql> SELECT @t1:=(@t2:=1)+@t3:=4,@t1,@t2,@t3;
MySQL服务器能够理解“||”和“&&”操作符,将其当作逻辑OR和AND,就像在C编程语言中那样。在MySQL服务器中,||和OR是同义词,&&和AND也是同义词。由于采用了该优异的语法体系,MySQL服务器不支持SQL针对字符串连接的“||”操作符,而采用了CONCAT()取而代之。由于CONCAT()能够接受任意数目的参量,很容易将使用“||”操作符的情况转换为MySQL服务器支持的类型。
默认情况下,所有的字符串比较均区分大小写,其分类顺序由当前字符集确定(默认为cp1252 Latin1)。如果你不喜欢该点,应使用BINARY属性或BINARY cast声明列,这样,就会使用基本的字符代码值进行比较,而不是词汇顺序。
“%”操作符等同于MOD()。也就是说“N % M”等同于MOD(N,M)。Cyuyan的程序员支持“%”,而且它也是为了兼容PostgreSQL而使用的。
BIT_COUNT()、CASE、ELT()、FROM_DAYS()、FORMAT()、IF()、PASSWORD()、ENCRYPT()、MD5()、ENCODE()、DECODE()、PERIOD_ADD()、PERIOD_DIFF()、TO_DAYS()、以及WEEKDAY()函数。
GROUP BY函数STD()、BIT_OR()、BIT_AND()、BIT_XOR()、以及GROUP_CONCAT()。请参见12.10节,“与GROUP BY子句同时使用的函数和修改程序”。
发表者
俞 伟军
位置在:
5/13/2007 09:35:00 PM
0
评论
标签: Assignment , MySQL , Operator
delete
The delete operator deletes an object, an object's property, or an element at a specified index in an array. The syntax is:
delete objectName
delete objectName.property
delete objectName[index]
delete property // legal only within a with statement
where objectName is the name of an object, property is an existing property, and index is an integer representing the location of an element in an array.
The fourth form is legal only within a with statement, to delete a property from an object.
You can use the delete operator to delete variables declared implicitly but not those declared with the var statement.
If the delete operator succeeds, it sets the property or element to undefined. The delete operator returns true if the operation is possible; it returns false if the operation is not possible.
x=42
var y= 43
myobj=new Number()
myobj.h=4 // create property h
delete x // returns true (can delete if declared implicitly)
delete y // returns false (cannot delete if declared with var)
delete Math.PI // returns false (cannot delete predefined properties)
delete myobj.h // returns true (can delete user-defined properties)
delete myobj // returns true (can delete if declared implicitly)
Deleting array elements
When you delete an array element, the array length is not affected. For example, if you delete a[3], a[4] is still a[4] and a[3] is undefined.
When the delete operator removes an array element, that element is no longer in the array. In the following example, trees[3] is removed with delete.
trees=new Array("redwood","bay","cedar","oak","maple")
delete trees[3]
if (3 in trees) {
// this does not get executed
}
If you want an array element to exist but have an undefined value, use the undefined keyword instead of the delete operator. In the following example, trees[3] is assigned the value undefined, but the array element still exists:
trees=new Array("redwood","bay","cedar","oak","maple")
trees[3]=undefined
if (3 in trees) {
// this gets executed
}
in
The in operator returns true if the specified property is in the specified object. The syntax is:
propNameOrNumber in objectName
where propNameOrNumber is a string or numeric expression representing a property name or array index, and objectName is the name of an object.
The following examples show some uses of the in operator.
// Arrays
trees=new Array("redwood","bay","cedar","oak","maple")
0 in trees // returns true
3 in trees // returns true
6 in trees // returns false
"bay" in trees // returns false (you must specify the index number,
// not the value at that index)
"length" in trees // returns true (length is an Array property)
// Predefined objects
"PI" in Math // returns true
myString=new String("coral")
"length" in myString // returns true
// Custom objects
mycar = {make:"Honda",model:"Accord",year:1998}
"make" in mycar // returns true
"model" in mycar // returns true
instanceof
The instanceof operator returns true if the specified object is of the specified object type. The syntax is:
objectName instanceof objectType
where objectName is the name of the object to compare to objectType, and objectType is an object type, such as Date or Array.
Use instanceof when you need to confirm the type of an object at runtime. For example, when catching exceptions, you can branch to different exception-handling code depending on the type of exception thrown.
For example, the following code uses instanceof to determine whether theDay is a Date object. Because theDay is a Date object, the statements in the if statement execute.
theDay=new Date(1995, 12, 17)
if (theDay instanceof Date) {
// statements to execute
}
new
You can use the new operator to create an instance of a user-defined object type or of one of the predefined object types Array, Boolean, Date, Function, Image, Number, Object, Option, RegExp, or String. On the server, you can also use it with DbPool, Lock, File, or SendMail. Use new as follows:
objectName = new objectType ( param1 [,param2] ...[,paramN] )
You can also create objects using object initializers, as described in "Using Object Initializers" on page 93.
See new in the Core JavaScript Reference for more information.
this
Use the this keyword to refer to the current object. In general, this refers to the calling object in a method. Use this as follows:
this[.propertyName]
Example 1. Suppose a function called validate validates an object's value property, given the object and the high and low values:
function validate(obj, lowval, hival) {
if ((obj.value < lowval) || (obj.value > hival))
alert("Invalid Value!")
}
You could call validate in each form element's onChange event handler, using this to pass it the form element, as in the following example:
Enter a number between 18 and 99:
onChange="validate(this, 18, 99)">
Example 2. When combined with the form property, this can refer to the current object's parent form. In the following example, the form myForm contains a Text object and a button. When the user clicks the button, the value of the Text object is set to the form's name. The button's onClick event handler uses this.form to refer to the parent form, myForm.
发表者
俞 伟军
位置在:
3/17/2007 12:22:00 AM
0
评论
标签: JavaScript , Operator