Resin 1.1
FAQ
Reference
JavaDoc
Demo
Java Tutorial
Getting Started
Configuration
Topics
JSP
XTP/XSL
JavaScript
JS Library
Source Text
Literals
Regexp
Operators
Objects
Functions
Statements
Java Wrapping
Literals
Literals
null | Returns the `null` value.
undefined | Returns the `undefined` value.
true | Returns the boolean `true` value.
false | Returns the boolean `false` value.
n[.m][e[+-]dd] | Returns a decimal floating point number.
0xhhh | Returns a hexidecimal number.
0ooo | Returns an octal integer.
'string' | Returns a string literal.
"string" | Returns a string literal
@"interpolated string" | Returns a string created by interpolating strings and variables.
@<<END | Returns a multiline interpolated string terminated by END.
{id_1:expr_1, ..., id_n:expr_n} | Returns a new object with assigned properties.
[expr_1, ..., expr_n] | Returns a new array with assigned values
/regexp/[i][g][m][x] | Returns a regular expression literal.
function(args) | Returns a function closure.
Literals
### null
Returns the `null` value. `null` is typically used to denote an object variable with no value. However, a variable which has never been assigned will have the value `undefined`. When converted to a number, `null` returns `0`. When converted to a string, `null` returns `"null"`. `null` has no properties and cannot be converted to an object. When a script tries to get a property of `null`, e.g. `null.foo`, Resin will throw an exception.
list = { first:1, rest:null }
### undefined
Returns the `undefined` value. Unassigned variables contain the `undefined` value and unassigned properties also contain the `undefined` value. When converted to a number, `undefined` returns `0`. When converted to a string, `undefined` returns `"undefined"`. `undefined` has no properties and cannot be converted to an object. When a script tries to get a property of `undefined`, e.g. `undefined.foo`, Resin will throw an exception.
var a a
| undefined
a = new Object() a.foo
| undefined
function foo(a) { return a } foo()
| undefined

### true

Returns the boolean `true` value.

When converted to a number, `true` returns `1`. When converted to a string, `true` returns `"true"`.

"" + true
| true
true + true
| 2
Boolean.prototype.a = 1 true.a
| 1

### false

Returns the boolean `false` value.

When converted to a number, `false` returns `0`. When converted to a string, `false` returns `"false"`.

"" + false
| false
false + false
| 0
Boolean.prototype.a = 1 false.a
| 1

### n[.m][e[+-]dd]

Returns a decimal floating point number. The precision of the number is 64 bits, the same as Java's double.

0
.1
1e10
.1e10
10.01e10

bad number
1.

### 0xhhh

Returns a hexidecimal number.

0xf
| 15
0xA0
| 160

### 0ooo

Returns an octal integer.

077
| 63
010
| 8

### 'string'

Returns a string literal. Strings may contain any character except the newline characters. Non-printable characters are included in the string by escaping the character as in the following table.

Character Escapes
Escape | Meaning
--- | ---
\b | backspace, 0x08
\e | escape, 0x1b
\f | form-feed, 0x0c
\n | line-feed, 0x0a
\r | carriage-return, 0x0d
\t | tab, 0x09
\v | vertical feed, 0xc
\cA | Control-A
\oooo | Octal escape
\xxx | Hex escape
\uxxxx | Unicode escape
\A | The character A

Example string literals
'"'
| "
"'"
| '
'\''
| '
'first\nsecond'
| first second
'\\\A'
| \A
'\x4012'
| @12
'\uaa55'.charCodeAt(0)
| 0xaa55
'$a'
| $a

### "string"

Returns a string literal String literals delimited by 'string' and "string" are equivalent. The script writer can choose either to minimize the number of escapes.

### @"interpolated string" | ### Resin 1.0

Returns a string created by interpolating strings and variables. The character '$' indicates that the value of the following identifier should be inserted into the string. Interpolated strings let the script writer create strings more clearly than the standard addition operator.

Equivalent Strings
a = 3; b = 4; c = 5; @"$a*$a + $b*$b = $c*$c"
| 3*3 + 4*4 = 5*5
a = 3; b = 4; c = 5; $a + '*' + $a + ' + ' + $b + '*' + $b + ' = ' + $c + '*' + $c
| 3*3 + 4*4 = 5*5

Example interpolation
sum = 2 + 2; @"2 + 2 = $sum"
| 2 + 2 = 4
a = [1,2,3] @"$(a[0]) $(a[1]) $(a[2])"
| 1 2 3
a = [1,2,3] @"$a[0]\n$a[1]"
| [object Object][0] [object Object][1]
a = 1; @"\$a"
| $a

### @<<END | ### Resin 1.0

Returns a multiline interpolated string terminated by END.

Because normal string literals cannot have newlines in them, creating long multiline strings gets messy and all the syntax for adding the lines together gets in the way of the string itself. Multiline strings eliminate extraneous syntax, allowing the script to clearly express the programmer's intentions.

Simple multiline string
a = 2 writeln(@<<END); This is a simple multiline string. It has $a lines. END
This is a simple multiline string. It has 2 lines.

Adding a Database Item
function addItem(title, author, description) { stmt = databasePool.createStatement(); stmt.executeUpdate(@<<END); INSERT INTO CATALOG values ( '$title', '$author', '$description' ) END

### {id_1:expr_1, ..., id_n:expr_n}

Returns a new object with assigned properties.

It is equivalent to the following:

o = new Object(); o.id_1 = expr_1; ... o.id_n = expr_n;

The Object toSource call returns a string using the object literal format.

### [expr_1, ..., expr_n]

Returns a new array with assigned values

It is equivalent to the following:

new Array(expr_1, ..., expr_n)

The Array toSource call returns a string using the array literal format.

### /regexp/[i][g][m][x]

Returns a regular expression literal. See regexp for a complete description of regular expression literals.

### function(args) { ... }

Returns a function closure. See function for a complete description of functions and closures.

function [name] (arg_1, ..., arg_n) { statement_list }

Sort with comparison function
a = [{a:19}, {a:1}, {a:13}] a.sort(function (a, b) { return a.a < b.a ? -1 : 1 }).toSource()
[{a:1}, {a:13}, {a:19}]

Regexp replace using replace function
"abcdefa".replace(/[ac]/g, function (a) { return a.charCodeAt(0) })
97b99def97

Source Text |  | Regexp

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