Resin 1.1
FAQ
Reference
JavaDoc
Demo
Java Tutorial
Getting Started
Configuration
Servlet
JSP
XTP/XSL
JavaScript
JS Library
Source Text
Literals
Regexp
Operators
Objects
Functions
Statements
Java Wrapping
Operators
Operators
a | Returns the value of the variable a.
`this` | Returns the value of the special variable `this`.
(a) | Returns the value of expression a.
obj.field | Returns the value named by the identifier field in obj.
obj[field_expr] | Returns the value named by the field_expr in the obj.
fun(arg_1, ..., arg_n) | Calls the function fun with arguments arg_1 through arg_n.
new fun(arg_1, ..., arg_n) | Creates a new object and calls fun to initialize it.
a++ | Returns a then increments it.
a-- | Returns a then decrements it.
++a | Increments a and returns the new value.
--a | Decrements a and returns the new value.
~ a | Returns the binary inverse of a.
! a | Returns the boolean inverse of a.
- a | Returns the negative of a.
+ a | Converts a to a number.
typeof a | Returns the type of a
delete a | Deletes the property a, returning true on success.
void a | Returns `undefined`
a * b | Multiplies a by b.
a / b | Divides a by b.
a % b | Returns the remainder of dividing a by b.
a + b | Concatenate when either a or b is a string and add otherwise.
a - b | Subtracts b from a.
a >> b | Arithmetically shifts a right by b bits.
a >>> b | Logically shifts a right by b bits.
a << b | Shifts a left by b bits.
a < b | True if a is less than b
a > b | True if a is greater than b
a <= b | True if a is less than or equal to b
a >= b | True if a is greater than or equal to b
a == b | True if a is equal to b
a != b | True if a is not equal to b.
a === b | True if a is strictly equal to b
a !== b | True if a is not strictly equal to b
a & b | Returns the logical and of a and b
a ^ b | Returns the logical exclusive or of a and b
a | b | Returns the logical or of a and b
a && b | Returns a if `!` a is true, otherwise returns b.
a || b | Returns a if a is true, otherwise returns b.
a ? b : c | Returns b if a is true, otherwise returns c.
a = b | Assigns b to a and returns b.
a x= b | Equivalent to `a = a x b`.
a, b | Evaluates a then b and returns b
Operators
### a
Returns the value of the variable a. Unlike Java variables, Javascript variables can store any value, i.e. they are untyped. So a can contain a number, a string, an object. Undeclared variables are global. Declared variables and function arguments are local to their declaring function. Declared but uninitialized variables have the value `undefined`. It is a runtime error to get the value of an undeclared and uninitialized variable. Setting an unused variable is allowed.
Variables are untyped
a = 3 a = "a"
var a = "a" a = {1,2,3}
if (true) a = 19; else a = [1,2,3]
Undeclared variables are global
function foo() { b = "local"; return b } foo() + ' ' + b
local local
Function arguments are local
var b = "global" function foo(b) { b = "local"; return b } foo() + ' ' + b
local global
Declared variables are local
var b = "global" function foo() { var b = "local"; return b } foo() + ' ' + b
local global
Variable initialization
b
| undefined variable `b'
var b; b
| undefined
b = 3; b
| 3

### `this`

Returns the value of the special variable `this`. `this` returns the value of the called object to allow method calls. See functions for a more complete description.

Basic use of `this`
function foo() { return this.a } obj = { a : 13, getA : foo } obj.getA()
13

### (a)

Returns the value of expression a.

### obj.field

Returns the value named by the identifier field in obj. Resin converts obj to an object, so literals like strings can have properties.

See objects for a complete discussion of object properties.

a = {a:3}; a.a
| 3
a = {b:"foo"}; a.b
| foo
a = {}; a.b = [1,2,3]; a.b
| 1,2,3
a = {c:{a:3}}; a.c.toSource()
| {a:3}
"abc".toSource()
| "abc"
"abc".replace(/b/, "B")
| aBc
null.foo
| null has no properties
var foo; foo.bar
| undefined has no properties

### obj[field_expr]

Returns the value named by the field_expr in the obj. field_expr can be any expression. Since properties are named by strings, Resin converts field_expr to a string before looking up the property.

See objects for a complete discussion of object properties.

a = {a:3}; a["a"]
| 3
a = {2:"foo"}; a[1 + 1]
| foo

### fun(arg_1, ..., arg_n)

Calls the function fun with arguments arg_1 through arg_n. See the function section for a more complete description.

function add(a, b) { return 10 * a + b; } add(1, 2)
12

### new fun(arg_1, ..., arg_n)

Creates a new object and calls fun to initialize it. The prototype of the new object is `fun.prototype`. The function call has `this` set to the new object. See the object section for a more complete description.

function car(color) { this.color = color; } car.prototype.wheels = 4 myCar = new car("red"); myCar.wheels + ' ' + myCar.color
4 red

### a++

Returns a then increments it.

a = 10 a++ + ' ' + a
| 10 11

### a--

Returns a then decrements it.

a = 10 a-- + ' ' + a
| 10 9

### ++a

Increments a and returns the new value.

a = 10 ++a + ' ' + a
| 11 11

### --a

Decrements a and returns the new value.

a = 10 --a + ' ' + a
| 9 9

### ~ a

Returns the binary inverse of a.

~0xf105
| 0xffff0efa
~-1
| 0

### ! a

Returns the boolean inverse of a.

! true
| false
! 0
| true
! 15
| false
! "0"
| false
! ""
| true

### - a

Returns the negative of a.

### + a

Converts a to a number.

### typeof a

Returns the type of a

### delete a

Deletes the property a, returning true on success.

### void a

Returns `undefined`

### a * b

Multiplies a by b.

### a / b

Divides a by b.

### a % b

Returns the remainder of dividing a by b.

### a + b

Concatenate when either a or b is a string and add otherwise.

"1" + 3
| 13
3 + "1"
| 31
3 + true
| 4

### a - b

Subtracts b from a.

### a >> b

Arithmetically shifts a right by b bits.

"1" >> 0
| 1
0x7f >> 4
| 7
-1 >> 16
| -1

### a >>> b

Logically shifts a right by b bits.

"1" >>> 0
| 1
0x7f >>> 4
| 7
-1 >>> 16
| 0xffff

### a << b

Shifts a left by b bits.

"1" << 2
| 4
0x7f << 4
| 0x7f0
-1 << 2
| -4

### a < b

True if a is less than b The comparison is a string comparison a and b are strings and a numeric comparison otherwise. This differs from the addition operation.

"12" < 2
| false
"12" < "2"
| true

### a > b

True if a is greater than b The comparison is a string comparison a and b are strings and a numeric comparison otherwise. This differs from the addition operation.

### a <= b

True if a is less than or equal to b The comparison is a string comparison a and b are strings and a numeric comparison otherwise. This differs from the addition operation.

### a >= b

True if a is greater than or equal to b The comparison is a string comparison a and b are strings and a numeric comparison otherwise. This differs from the addition operation.

### a == b

True if a is equal to b The conversion rules are given in the following table:

a | b | comparison type
--- | --- | ---
null | undefined | true
null or undefined | anything | false
string | object | string
number | object | number
number | string | number
object | object | strict equality
| number

### a != b

True if a is not equal to b. The comparison is as for equality.

### a === b

True if a is strictly equal to b No conversions are performed.

### a !== b

True if a is not strictly equal to b No conversions are performed.

### a & b

Returns the logical and of a and b

0x1010 & 0x1100
| 0x1000

### a ^ b

Returns the logical exclusive or of a and b

0x1010 ^ 0x1100
| 0x0110

### a | b

Returns the logical or of a and b

0x1010 | 0x1100
| 0x1110

### a && b

Returns a if `!` a is true, otherwise returns b. The evaluation short-circuits if a is false, i.e. b is not evaluated.

0 && foo()
| 0 // foo() is not called
null && foo()
| null // foo() is not called
15 && foo()
| foo()

### a || b

Returns a if a is true, otherwise returns b. The evaluation short-circuits if a is true, i.e. b is not evaluated.

0 || foo()
| foo()
"0" || foo()
| "0" // foo() is not called
true || foo()
| foo()

### a ? b : c

Returns b if a is true, otherwise returns c.

null ? foo() : bar()
| bar() // foo() is not called
"0" ? foo() : bar()
| foo() // bar() is not called

### a = b

Assigns b to a and returns b.

See watch.

(a = 3) + 9 a
| 12 3
a["foo"] = 3 a.foo
| 3 3

### a x= b

Equivalent to `a = a x b`.

a = 3; a *= 2
| 6
a = 3; a /= 2
| 1.5
a = 3; a %= 2
| 1
a = 3; a += 1
| 4
a = "3"; a += 1
| 31
a = 3; a -= 1
| 2
a = 3; a <<= 2
| 12
a = -16; a >>= 2
| -4
a = -1; a >>>= 16
| 0xffff
a = 0x1100; a &= 0x1010
| 0x1000
a = 0x1100; a ^= 0x1010
| 0x0110
a = 0x1100; a |= 0x1010
| 0x1110

### a, b

Evaluates a then b and returns b

a = 1, ++a
| 2

Regexp |  | Objects

Copyright © 1998-2000 Caucho Technology. All rights reserved.
Last modified: Thu, 16 Sep 1999 14:56:48 -0700 (PDT)