ECMAScript Reference
All of the ECMAScript operators, statements, and core objects are
supported by VoiceGenie.
Here are some other sites that have ECMAScript/JavaScript
reference documentation:
http://www.mozilla.org/js/
http://www.mozilla.org/js/language
http://www.mozilla.org/js/scripting
http://www.devguru.com/Technologies/ecmascript/quickref/javascript_index.html
Functions
|
Function
|
Description
|
|
_VGGetInfo
(VoiceGenie-defined)
|
A global function that allows applications to access information about the
IP Media Server and the running page, as well as any other custom
information that is defined.
The _VGGetInfo() function takes in a string argument
and returns a string value, or an empty string if the specified
parameter name is not recognized. The 3 currently defined
parameters can be used as follows:
-
_VGGetInfo('host_ip') - returns the IP Media
Server IP address
-
_VGGetInfo('host_name') - returns the IP Media
Server hostname
-
_VGGetInfo('running_uri') - returns the URI
of the current VoiceXML page
Additional parameters can be defined for access to custom
information with this function. This is done through the VoiceXML
Interpreter Configuration.
|
Operators
|
Category
|
Operator
|
Description
|
|
Arithmetic
|
+ |
Adds 2 numbers.
|
++ |
Increments a number.
|
- |
As a unary operator, negates the value of its argument. As
a binary operator, subtracts 2 numbers.
|
-- |
Decrements a number.
|
* |
Multiplies 2 numbers.
|
/ |
Divides 2 numbers.
|
% |
Computes the integer remainder of dividing 2 numbers.
|
|
String
|
+
|
Concatenates 2 strings.
|
|
+=
|
Concatenates 2 strings and assigns the result to the first
operand.
|
|
Logical Operators
|
&&
|
(Logical AND) Returns true if both logical operands are
true. Otherwise, returns false.
|
|
||
|
(Logical OR) Returns true if either logical expression is
true. If both are false, returns false.
|
|
!
|
(Logical negation) If its single operand is true, returns
false; otherwise, returns true.
|
|
Bitwise Operators
|
& |
(Bitwise AND) Returns a one in each bit position if bits
of both operands are ones.
|
^ |
(Bitwise XOR) Returns a one in a bit position if bits of
one but not both operands are one.
|
| |
(Bitwise OR) Returns a one in a bit if bits of either
operand is one.
|
~ |
(Bitwise NOT) Flips the bits of its operand.
|
<< |
(Left shift) Shifts its first operand in binary
representation the number of bits to the left specified in the second
operand, shifting in zeros from the right.
|
>> |
(Sign-propagating right shift) Shifts the first operand in
binary representation the number of bits to the right specified in the second
operand, discarding bits shifted off.
|
>>> |
(Zero-fill right shift) Shifts the first operand in binary
representation the number of bits to the right specified in the second
operand, discarding bits shifted off, and shifting in zeros from the left.
|
|
Assignment
|
= |
Assigns the value of the second operand to the first
operand.
|
+= |
Adds 2 numbers and assigns the result to the first.
|
-= |
Subtracts 2 numbers and assigns the result to the first.
|
*= |
Multiplies 2 numbers and assigns the result to the first.
|
/= |
Divides 2 numbers and assigns the result to the first.
|
%= |
Computes the modulus of 2 numbers and assigns the result
to the first.
|
&= |
Performs a bitwise AND and assigns the result to the first
operand.
|
^= |
Performs a bitwise XOR and assigns the result to the first
operand.
|
|= |
Performs a bitwise OR and assigns the result to the first
operand.
|
<<= |
Performs a left shift and assigns the result to the first
operand.
|
>>= |
Performs a sign-propagating right shift and assigns the
result to the first operand.
|
>>>= |
Performs a zero-fill right shift and assigns the result to
the first operand.
|
|
Comparison
|
==
|
Returns true if the operands are equal.
|
|
!=
|
Returns true if the operands are not equal.
|
|
>
|
Returns true if left operand is greater than right
operand.
|
|
>=
|
Returns true if left operand is greater than or equal to
right operand.
|
|
<
|
Returns true if left operand is less than right operand.
|
|
<=
|
Returns true if left operand is less than or equal to
right operand.
|
|
Special
|
?:
|
Performs simple "if ? then : else"
|
|
,
|
Evaluates two expressions and returns the result of the
second expression.
|
|
delete
|
Deletes an object property or an element at a specified
index in an array.
|
|
new
|
Creates an instance of an object.
|
|
this
|
Refers to the current object.
|
|
typeof
|
Returns a string indicating the type of the unevaluated
operand.
|
|
void
|
Specifies an expression to be evaluated without returning
a value.
|
Statements
|
Statement
|
Description
|
|
break
|
Terminates the current while or for loop and transfers
program control to the statement following the terminated loop.
|
|
continue
|
Terminates execution of the block of statements in a while
or for loop, and continues execution of the loop with the next iteration.
|
|
delete
|
Deletes an object's property or an element of an array.
|
|
do
...
while(condition)
|
Executes its statements until the test condition evaluates
to false. Statement is executed at least once.
|
|
for (init; condition; increment)
|
A loop that consists of three optional expressions,
enclosed in parentheses and separated by semicolons, followed by a block of
statements executed in the loop.
|
|
for (var in object)
|
Iterates a specified variable over all the properties of
an object. For each distinct property, JavaScript executes the specified
statements.
|
|
function
|
Declares a JavaScript function name with the specified
parameters. Acceptable parameters include strings, numbers, and objects.
|
|
if (condition) ... else
|
Executes a set of statements if a specified condition is
true. If the condition is false, another set of statements can be executed.
|
|
labeled
|
Provides an identifier that can be used with break or
continue to indicate where the program should continue execution.
|
|
return
|
Statement that specifies the value to be returned by a
function.
|
|
switch (expression)
case label:
|
Evaluates an expression and attempt to match the
expression's value to a case label.
|
|
var
|
Declares a variable, optionally initializing it to a
value.
|
|
while (condition) ...
|
Creates a loop that evaluates an expression, and if it is
true, executes a block of statements.
|
|
with (object) ...
|
Establishes the default object for a set of statements.
|
|
//
|
Defines comment until end of the line.
|
|
/* ... */
|
Defines comment within the operators.
|
Core Objects
Array Object
|
Property
|
Description
|
|
length
|
Size of the array.
|
|
index
|
Position of matched substring
(from RegExp object)
|
|
input
|
Original string for matching
(from RegExp object)
|
|
Method
|
Description
|
|
concat(array1)
|
Joins two arrays into one array.
|
|
join(separator)
|
Joins array element into a
string, separated by separator (Defaults to ",")
|
|
pop
|
Removes last element from an
array and returns that element.
|
|
push(e1, e2 ...)
|
Adds one or more elements to the
end of the array and returns the last element.
|
|
reverse
|
Reverses the elements in the
array.
|
|
shift
|
Removes the first element from
an array and returns that element.
|
|
slice(begin, end)
|
Extracts elements from index
begin to end and returns a new array.
|
|
sort
|
Sorts the elements of an array
|
|
splice
|
Change content of array by
adding and removing elements.
|
|
toString
|
Returns string representation of
array
|
|
unshift(e1, e2 ...)
|
Adds one or more elements to the beginning of the array
and returns new array length.
|
Boolean Object
|
Method
|
Description
|
|
toString
|
Returns string representation of
Boolean.
|
Date Object
|
Method
|
Description
|
|
getDate
|
Returns the day of the month.
|
|
getDay
|
Returns the day of the week.
|
|
getHours
|
Returns the hour.
|
|
getMinutes
|
Returns the minutes.
|
|
getMonth
|
Returns the month.
|
|
getSeconds
|
Returns the seconds.
|
|
getTime
|
Returns the numeric value corresponding to the time.
|
|
getTimezoneOffset
|
Returns the time-zone offset in minutes for the current
locale.
|
|
getYear
|
Returns the year.
|
|
parse
|
Returns the number of milliseconds in a date string since
January 1, 1970, 00:00:00, local time.
|
|
setDate
|
Sets the day of the month.
|
|
setHours
|
Sets the hours.
|
|
setMinutes
|
Sets the minutes.
|
|
setMonth
|
Sets the month.
|
|
setSeconds
|
Sets the seconds.
|
|
setTime
|
Sets the value of a Date object.
|
|
setYear
|
Sets the year.
|
|
toGMTString
|
Converts a date to a string, using the Internet GMT
conventions.
|
|
toLocaleString
|
Converts a date to a string, using the current locale's
conventions.
|
|
UTC
|
Returns the number of milliseconds in a Date object
since January 1, 1970, 00:00:00, Universal Coordinated Time (GMT).
|
Math Object
|
Property
|
Description
|
|
E
|
Euler's constant, approximately 2.718.
|
|
LN10
|
Natural logarithm of 10, approximately 2.302.
|
|
LN2
|
Natural logarithm of 2, approximately 0.693.
|
|
LOG10E
|
Base 10 logarithm of E, approximately 0.434.
|
|
PI
|
Pi, approximately 3.14159.
|
|
SQRT1_2
|
Square root of 1/2, approximately 0.707.
|
|
SQRT2
|
Square root of 2, approximately 1.414.
|
|
Method
|
Description
|
|
abs
|
Returns the absolute value of a number.
|
|
acos
|
Returns the arccosine (in radians) of a number.
|
|
asin
|
Returns the arcsine (in radians) of a number.
|
|
atan
|
Returns the arctangent (in radians) of a number.
|
|
atan2
|
Returns the arctangent of the quotient of its arguments.
|
|
ceil
|
Returns the smallest integer greater than or equal to a
number.
|
|
cos
|
Returns the cosine of a number.
|
|
exp
|
Returns Enumber, where number
is the argument, and E is Euler's constant, the base of the natural
logarithms.
|
|
floor
|
Returns the largest integer less than or equal to a
number.
|
|
log
|
Returns the natural logarithm (base E) of a number.
|
|
max
|
Returns the greater of two numbers.
|
|
min
|
Returns the lesser of two numbers.
|
|
pow
|
Returns base to the exponent power, that is, baseexponent.
|
|
random
|
Returns a pseudo-random number between 0 and 1.
|
|
round
|
Returns the value of a number rounded to the nearest
integer.
|
|
sin
|
Returns the sine of a number.
|
|
sqrt
|
Returns the square root of a number.
|
|
tan
|
Returns the tangent of a number.
|
Number Object
|
Property
|
Description
|
|
MAX_VALUE
|
The largest representable
number.
|
|
MIN_VALUE
|
The smaller representable
number.
|
|
NaN
|
Not a number value.
|
|
NEGATIVE_INFINITY
|
Negative infinite value for
overflow.
|
|
POSITIVE_INFINITY
|
Infinite value for overflow.
|
|
Method
|
Description
|
|
toString
|
Returns string representation of a number.
|
Object Object
|
Method
|
Description
|
|
eval
|
Evaluates a string of ECMAScript
in the context of this object.
|
|
toString
|
Returns the string
representation of this object.
|
|
valueOf
|
Returns the primitive value of
the specified object.
|
String Object
|
Property
|
Description
|
|
length
|
Returns length of the string.
|
|
Method
|
Description
|
|
charAt
|
Returns the character at the specified index.
|
|
charCodeAt
|
Returns a number indicating the ISO-Latin-1 codeset value
of the character at the given index.
|
|
concat
|
Combines the text of two strings and returns a new string.
|
|
fromCharCode
|
Returns a string from the specified sequence of numbers
that are
ISO-Latin-1 codeset values.
|
|
indexOf
|
Returns the index within the calling String
object of the first occurrence of the specified value.
|
|
lastIndexOf
|
Returns the index within the calling String
object of the last occurrence of the specified value.
|
|
match
|
Matches a regular expression against a string.
|
|
replace
|
Finds a match between a regular expression and a string,
and to replace the matched substring with a new substring.
|
|
search
|
Executes the search for a match between a regular
expression and a specified string.
|
|
slice
|
Extracts a section of a string and returns a new string.
|
|
split
|
Splits a string into an array of strings by separating the
string into substrings.
|
|
substr
|
Returns the characters in a string beginning at the
specified location through the specified number of characters.
|
|
substring
|
Returns the characters in a string between two indexes
into the string.
|
|
toLowerCase
|
Returns the calling string value converted to lowercase.
|
|
toUpperCase
|
Returns the calling string value converted to uppercase.
|
RegExp Object
|
Property
|
Description
|
|
$1...$9
|
Parenthesized substring matches, if any.
|
|
global
|
Whether or not to test the regular expression against all
possible matches in a string, or only against the first.
|
|
ignoreCase
|
Whether or not to ignore case while attempting a match in
a string.
|
|
input or $_
|
The string against which a regular expression is matched.
|
|
lastIndex
|
The index at which to start the next match.
|
|
lastMatch or $&
|
The last matched characters.
|
|
lastParen
|
The last parenthesized substring match, if any.
|
|
leftContext or $`
|
The substring preceding the most recent match.
|
|
multiline or $*
|
Whether or not to search in strings across multiple lines.
|
|
right Context or $'
|
The substring following the most recent match.
|
|
source
|
The text of the pattern.
|
|
Method
|
Description
|
|
compile
|
Compiles a regular expression object.
|
|
exec
|
Executes a search for a match in its string parameter.
|
|
test
|
Tests for a match in its string parameter.
|
Notes
1. Numeric literals starting with 0 are treated as octal numbers
The JavaScript engine treats numeric literals starting with 0 as octal
numbers (base 8). If such numeric literals are specified within scripts
or as an ECMAScript expression in any attribute, the numbers will be
converted from an octal number to a decimal number when the expressions
are evaluated by the JavaScript engine. This may cause unexpected results.
For example, if you are creating an object to send an ANI with an outbound
call, you may get unexpected results for ANIs that start with 0. Here are
three different cases:
-
<assign name="callvars.ani" expr="4161234444"/>
-
<assign name="callvars.ani" expr="0146504262"/>
-
<assign name="callvars.ani" expr="0153080631"/>
In case (1), the numeric literal does not start with 0. So it will be
treated as a decimal number when the expression is evaluated, and the
same string of digits will be sent as the ANI with the outbound call.
In case (2), the numeric literal starts with 0, so it will be treated as
an octal number. It is a valid octal number (all the digits are less than
8), so when the expression is evaluated, it will be converted to its
decimal equivalent, 26904754. Therefore, the string of digits that are sent
as the ANI with the outbound call will be different from what was
originally specified.
In case (c), the numeric literal starts with 0, so it will be treated as
an octal number. However, it is not a valid octal number (one of the
digits is 8), so it cannot be converted to its decimal equivalent. In this
case, the result of evaluating the expression is the decimal value
153080631, and the same string of digits (minus the leading 0) will be
sent as the ANI with the outbound call.
In any case, wrapping the number in single quotes will ensure that it will
be treated as a string. For numbers starting with 0, this means that there
is no danger of it being converted. For example, the following variable
setting ensures that the expected string of digits will be sent as the ANI
with the outbound call:
<assign name="callvars.ani" expr="'0146504262'"/>
Reserved Words
Avoid using the reserved words in this list as variables, functions, methods,
or object names. Some of these words are keywords; others are reserved for
future use. Use of some of these reserved words will cause an
error event to be thrown.
The words in the list that do not currently cause an error should still be
avoided, as they might cause an error in the future.
- abstract
- boolean
- break
- byte
- case
- catch
- char
- class
- comment
- const
- continue
|
- debugger
- default
- delete
- do
- double
- else
- enum
- export
- extends
- false
|
- final
- finally
- float
- for
- function
- goto
- if
- implements
- import
- in
|
- instanceof
- int
- interface
- label
- long
- native
- new
- null
- package
- private
|
- protected
- public
- return
- short
- static
- super
- switch
- synchronized
- this
- throw
|
- throws
- transient
- true
- try
- typeof
- var
- void
- volatile
- while
- with
|
|