Anda di halaman 1dari 24

JavaScript Quick Reference

Part No. 520-0007-02

VoiceXML uses the JavaScript language (also called ECMAScript) for manipulating data. The BeVocal VoiceXML interpreter supports
JavaScript 1.5; this version of the language supports latest the ECMA-262 Edition 3 specification. For official documentation on this
language, see http://www.mozilla.org/js/language/.
This document provides a quick reference to the JavaScript features available in BeVocal VoiceXML. It is organized as follows:
• VoiceXML Markup Characters
• Operators
• Statements
• Global Properties
• Global Functions
• Standard Objects
• BeVocal Constants (Extensions)
• BeVocal Objects (Extensions)

VoiceXML Markup Characters

VoiceXML documents can contain JavaScript code in two contexts:


• Many attributes accept a JavaScript expression as the attribute value.
• The <script> element contains arbitrary JavaScript code.
JavaScript code can contain 3 characters which have meaning in JavaScript but which also have meaning as VoiceXML markup
characters. Whenever JavaScript inside your VoiceXML document contains one of these characters, you must somehow “escape” the
character.
For a JavaScript expression that is the value of an attribute, you must escape the characters using the corresponding escape sequence.
For example, assume you wanted to have the following JavaScript expression as the value of the cond attribute of the <if> tag:
JAVASCRIPT QUICK REFERENCE

balance < minbalance


You would write the tag as follows:
<if cond="balance &lt; minbalance">
On the other hand, if you’re writing an entire section of JavaScript code inside a <script> element, it is cleaner to wrap all of the code in a
CDATA section. For example, a script containing the factorial function might be written as follows:
<script>
<![CDATA[
function factorial(n) {
return (n <= 1) ? 1 : n * factorial(n-1);
}
]]>
</script>
The characters you must escape are as follows:

Character Escape sequence


< &lt;
> &gt;
& &amp;

Operators

To see more complete example code for using JavaScript within VoiceXML, see the JavaScript samples on the VoiceXML Samples page.

Arithmetic

Operator Description Example


+ Adds two numbers. <value expr="2+3"/>
++ Increments a number. <var name="num" expr="2"/>
<value expr="++num"/>
- Subtracts the second number from the first. <value expr="2-3"/>
-- Decrements a number. <value expr="--num"/>
* Multiply two numbers. <value expr="2*3"/>

JAVASCRIPT QUICK REFERENCE 2


Operators

Operator Description Example


/ Divide two numbers. <value expr="2/3"/>
% Integer modulo of two numbers. <value expr="2%3"/>

String

Operator Description Example


+ Concatenates two strings. <value expr="'cat'+'fish'"/>
+= Concatenates two strings, and sets the first to the result. <var name="str"/>
<value expr="str+='fish'"/>

Logical

Operator Description Example


&& Logical AND. <var name="truth" expr="true"/>
<var name="falsity" expr="false"/>
<value expr="truth &amp;&amp; falsity"/>
|| Logical OR. <value expr="truth || falsity"/>
! Logical Negate. <value expr="!truth"/>

Bitwise

Operator Description Example


& Bitwise AND. <value expr="10 &amp; 20"/>
^ Bitwise Exclusive OR. <value expr="10 ^ 20"/>
| Bitwise OR. <value expr="10 | 20"/>
~ Bitwise COMPLEMENT. <value expr="~-3"/>
<< Arithmetic left shift (shifts in zeroes). <value expr="10&lt;&lt;2"/>
>> Arithmetic right shift (shifts in the sign bit). <value expr="10&gt;&gt;2"/>
>>> Logical right shift (shifts in zeroes) <value expr="10&gt;&gt;&gt;2"/>

3 JAVASCRIPT QUICK REFERENCE


JAVASCRIPT QUICK REFERENCE

Assignment

Operator Description Example


= Set the first operand to the value of the second operand. <var name="result"/>
<value expr="result=100"/>
+= Add two numbers, and set the first operand to the result. <value expr="result+=15"/>
-= Subtract two numbers, and set the first operand to the result. <value expr="result-=15"/>
*= Multiply two numbers, and set the first operand to the result. <value expr="result*=15"/>
/= Divide two numbers, and set the first operand to the result. <value expr="result/=15"/>
%= Modulo two numbers, and set the first operand to the result. <value expr="result%=15"/>
&= Bitwise AND two numbers, and set the first operand to the result. <value expr="result&amp;=10"/>
^= Bitwise XOR two numbers, and set the first operand to the <value expr="result^=10"/>
result.
|= Bitwise OR two numbers, and set the first operand to the result. <value expr="result|=10"/>
<<= Arithmetic left shift, and set the first operand to the result. <value expr="result&lt;&lt;=10"/>
>>= Arithmetic right shift, and set the first operand to the result. <value expr="result&gt;&gt;=10"/>
>>>= Logical right shift, and set the first operand to the result. <value expr="result&gt;&gt;&gt;=10"/>

Comparison

Operator Description Example


== equals. <value expr="numberone == stringnum"/>
=== strictly equals (does not do operand casting). <value expr="numberone === stringnum"/>
!= not equals. <value expr="numberone != stringnum"/>
!== strictly not equals (does not do operand casting). <value expr="numberone !== stringnum"/>
> greater than. <value expr="numberone &gt; stringnum"/>
>= greater than or equal. <value expr="numberone &gt;= stringnum"/>
< less than. <value expr="numberone &lt; stringnum"/>
<= less than or equal. <value expr="numberone &lt;= stringnum"/>
in Is the first operand a property of the second operand (an object). <var name="err" expr="new Error('hi')"/>
<value expr="'message' in err"/>
instanceof Is the first operand an instance of the second object. <var name="theDate" expr="new Date()"/>
<value expr="theDate instanceof Date"/>

JAVASCRIPT QUICK REFERENCE 4


Operators

Special

Operator Description Example


?: If first operand is true, use the second operand, else use <value expr="truth?'true':'false'"/>
the third operand.
, Evaluate operands sequentially, and return the result of <value expr="numbertwo=50,++numbertwo"/>
the second operand.
( ) Grouping. <value expr=
"(truth?((numberone &lt; 100)?50:100):300)+200"/>
delete Delete an object property, or a specific element of an <!--after deleting, 3rd element returns undefined-->
array. <value expr="delete myarray[2],myarray[2]"/>
new Create an instance of an object. <var name="myCar"
expr="new car('bmw','z3','1998')"/>
this Refers to the current object. <script>
function car(make, model, year){
this.make = make ;
this.model = model ;
this.year = year ;
}
</script>
typeof Returns a string representing the type of the operand. <value expr="typeof myarray"/>
void Specifies that an expression should be evaluated, but <value expr="javascript:void(++numberone)"/>
not return a result.

5 JAVASCRIPT QUICK REFERENCE


JAVASCRIPT QUICK REFERENCE

Statements

Declarations

Statement Description Example


function Declares a function. <script>
function car(make, model, year) {
this.make = make ;
this.model = model ;
this.year = year ;
}
</script>
var Declares a variable, with optional initialization. <var name="result"/>
<var name="theDate" expr="new Date()"/>

Control Flow

Statement Description Example


{ } Grouping. See for example.
; Empty statement.
break Terminates the current while or for loop. See switch example.
continue Without a label, go to the next step in a loop; See while example.
with a label, go to the labelled statement.
default: Labels the default behavior in a switch See switch example.
statement.
delete Delete an object property, or a specific element <!--after deleting, 3rd element returns undefined-->
of an array. <value expr="delete myarray[2],myarray[2]"/>
do...while Loop until the test returns false. Statements are <script>
always executed at least once. ...
do {
i+=1;
processItem(myArray[i]);
}
while (myArray[i] != "stop")
</script>

JAVASCRIPT QUICK REFERENCE 6


Statements

Statement Description Example


for Loop construct, as in C or Java. <script>
// from the Haiku sample.
function tts(line)
{
bevocal.log("tts:line="+line);
res = "";
for( var i = 0; i < line.length; i++) {
res = res+" "+line[i].firstChild.nodeValue;
bevocal.log("res="+res);
}
return res;
}
</script>
for...in Iterate over the properties of an object. <script>
...
for (item in myArray)
processItem(myArray[i]);
</script>
if...else Conditionally executes a block of code. See try...catch example.
label: Defines a label for use with break or continue See while example.
statements.
return Specify a value to return from a function. <script>
var multFun =
new Function("x", "y", "return x * y")
</script>

7 JAVASCRIPT QUICK REFERENCE


JAVASCRIPT QUICK REFERENCE

Statement Description Example


switch...case: Switch statement. <script>
<![CDATA[
//Returns fruit's price/pound or null if not available.
function switchAndBreakTest(fruit) {
var result = "";
switch (fruit) {
case "oranges" :
result="0.59";
break;
case "strawberries" :
result="0.32";
break;
default :
result=null;
}
return result;
}
]]>
</script>
throw Throw a user-defined exception. See try...catch example.
try...catch... Block of statements to try and a set of <script>
finally responses to handle exceptions. // from the Haiku sample.
...
syll=0;
for( var w = 0 ; w < line.length && syll <= s; w++) {
try {
syll = syll + parseInt(
line[w].getAttributeNode("syllables").value, 10);
bevocal.log("w="+line[w].firstChild.nodeValue+
" syll="+syll);
} catch (e) {
bevocal.log("parseInt Exception="+e);
}
}
...
</script>

JAVASCRIPT QUICK REFERENCE 8


Statements

Statement Description Example


while Loop as long as condition is true. Statements <script>
might not be executed at all. <![CDATA[
//Returns the total price, with discount for dozens.
//Do not code like this. It is only an example! :)
function whileAndContinueLabelTest(quantity, price) {
var totalprice=0;
var qm=0;
startwhile:
while (quantity > 0) {
if ( quantity>=12 && (quantity%12>0) ) {
qm = quantity%12;
totalprice=(quantity-qm)*0.95*price;
quantity=qm;
continue startwhile;
}
totalprice= Math.round(
(totalprice+quantity*price)*100)/100;
quantity=0;
}
return totalprice;
}
]]>
</script>
with Establishes the default context for a set of <script>
statements. var a, x, y;
var r=10;
with (Math) {
a = PI * r * r;
x = r * cos(PI);
y = r * sin(PI/2);
</script>

9 JAVASCRIPT QUICK REFERENCE


JAVASCRIPT QUICK REFERENCE

Comments

Statement Description Example


// Comment operator (ignores the rest of the current line). <script>
var verbs; // an array of verbs
var nouns; // an array of nouns
</script>
/* */ Comment operator (ignores the intervening text). <script>
/* Return random number between 0 and len. */
function rnd(len) {
return(Math.round(Math.random()* len));
}
</script>

Global Properties

Property Description Example


Infinity A value representing infinity. <value expr="Infinity"/>
NaN A value representing not a number. <value expr="Number.NaN"/>
undefined The value undefined. <value expr="undefined"/>

JAVASCRIPT QUICK REFERENCE 10


Global Functions

Global Functions

Function Description Example


decodeURI Create a new URI from an encoded <script>
URI by replacing escape sequences <![CDATA[
with the special characters they var uri =
represent. "http://www.my.fr/cgi-bin/script.pl?Text=le texte
decodeURIComponent Create a new version of a transmis&Nom=Serge François";
componenet of a URI from an var uri1 = encodeURI(uri);
encoded URI component by replacing // uri1 is
escape sequences with the special "http://www.my.fr/cgi-bin/script.pl?Text=le%20text
characters they represent. e%20transmis&Nom=Serge%20Fran%e7%af%a9s"
encodeURI Create a new URI by replacing
certain special characters with var uri2 = encodeURIComponent(uri);
escape sequences. encodeURI does // uri2 is
not encode ":", "/", ";", and "?". "http%3a%2f%2fwww.my.fr%2fcgi-bin%2fscript.pl%3fTe
Use encodeURIComponent to xt%3dle%20texte%20transmis%26Nom%3dSerge%20Fran%e7
encode these characters. %af%a9s"
encodeURIComponent Create a new version of components
var uri3 = decodeURI(uri1);
of a URI by replacing certain special
var uri4 = decodeURIComponent(uri2);
characters with escape sequences.
// uri3 & uri4 are both the same as uri
]]>
</script>
eval Evaluate a string of JavaScript code. <value expr="eval(10)"/>
isFinite True if the argument is a finite <value expr="isFinite(Math.PI)"/>
number.
isNaN True if the argument isn’t a number. <value expr="isNaN(stringvar)"/>
parseFloat Create a floating point number from a <value expr="parseFloat(20.3)"/>
string.
parseInt Create an integer from a string. <value expr="parseInt(20.3)"/>
bevocal.cookies.addClientCookie Extension. Sets a cookie on the bevocal.cookies.addClientCookie("cafe.bevocal.com"
VXML client. , "user_1", "1234");
bevocal.cookies.deleteClientCookie Extension. Deletes a cookie on the bevocal.cookies.deleteClientCookie("user_2");
VXML client.

11 JAVASCRIPT QUICK REFERENCE


JAVASCRIPT QUICK REFERENCE

Function Description Example


bevocal.cookies.getClientCookie Extension. Gets the value of a cookie user_1 = bevocal.cookies.getClientCookie(null,
on the VXML client. "user_1");
bevocal.cookies.getClientCookies Extension. Returns a HashMap of all user = bevocal.cookies.getClientCookies(null);
key/value cookie pairs.
bevocal.enroll.removeEnrolledPhras Extension. Deletes enrolled phrases <script>
e from grammars. bevocal.enroll.removeEnrolledPhrase(
"ADDRESSBOOK", theSpeaker, thePhrase, null)
</script>
bevocal.getProperty Extension. Gets the value of a <value expr="bevocal.getProperty('universals')"/>
VoiceXML property.
bevocal.getVersion Extension. Returns the VoiceXML <value expr="bevocal.getVersion()"/>
interpreter version.
bevocal.log Extension. Writes a message to the <script>
BeVocal Café website. bevocal.log("Getting user name");
</script>

Standard Objects

Object

Method Description Example


hasOwnProperty() Whether the argument is a native property of this <var name="myarray" expr="new Array (1,2,3)"/>
Object. <value expr="myarray.hasOwnProperty('length')"/>
toLocaleString() Returns a string representing the Object, using <value expr="mydate.toLocaleString()"/>
locale conventions.
toString() Returns a string representing the Object. <value expr="mydate.toString()"/>
valueOf() Returns the primitive value of an Object. <value expr="mydate.valueOf()"/>

JAVASCRIPT QUICK REFERENCE 12


Standard Objects

Array

Property/Method Description Example


length The number of elements in the array. Read/write. <value expr="myArray.length"/>
concat() Concatenates two arrays into an array. Does not change <value expr="myArray.concat(myArray2).join()"/>
either original array.
join() Joins the elements of an array into a string. Does not <value expr="myArray.join()"/>
change the array.
pop() Removes the last element, and returns that element. <value expr="myArray.pop()"/>
Changes the array.
push() Adds one or more elements to the end of an array, and <value expr="myArray.push('zebra')"/>
returns the length of the new array. Changes the array.
reverse() Reverses the elements of an array. Changes the array. <value expr="myArray.reverse().join()"/>
shift() Removes the first element, and returns that element. <value expr="myArray.shift()"/>
Changes the array.
slice() Extracts a section of an array, and returns it as a new array. <value expr="myArray2.slice(2,4).join()"/>
Does not change the original array.
sort() Sorts the elements. Changes the array. <value expr="myArray2.sort().join()"/>
splice() Removes elements, and adds elements at the same time. <value
Returns the section that was removed as a new array. expr="myArray2.splice(2,3,'a','b').join()"/>
Changes the originalarray.
unshift() Adds one or more elements to the beginning of an array; <value
returns the new length of the array. Changes the array. expr="myArray2.unshift('fred', 'wilma')"/>

Boolean
No special properties or methods.

Date

Property/Method Description Example


getDate() Returns the day of the month for the specified date, <var name="now" expr="new Date()"/>
in local time. <value expr="now.getDate()"/>
getDay() Returns the day of the week for the specified date, <value expr="now.getDay()"/>
in local time.
getFullYear() Returns the year in the specified date, in local time. <value expr="now.getFullYear()"/>
getHours() Returns the hour in the specified date, in local time. <value expr="now.getHours()"/>

13 JAVASCRIPT QUICK REFERENCE


JAVASCRIPT QUICK REFERENCE

Property/Method Description Example


getMilliseconds() Returns the milliseconds in the specified date, in <value expr="now.getMilliseconds()"/>
local time.
getMinutes() Returns the minutes in the specified date, in local <value expr="now.getMinutes()"/>
time.
getMonth() Returns the month in the specified date, in local <value expr="now.getMonth()"/>
time.
getSeconds() Returns the seconds in the specified date, in local <value expr="now.getSeconds()"/>
time.
getTime() Returns a numeric value representing the time for a <value expr="now.getTime()"/>
specific date, in local time.
getTimezoneOffset() Returns the time zone offset in minutes for the <value expr="now.getTimezoneOffset()"/>
current locale.
getUTCDate() Returns the day of the month for the specified date, <value expr="now.getUTCDate()"/>
in universal time.
getUTCDay() Returns the day of the week for the specified date, <value expr="now.getUTCDay()"/>
in universal time.
getUTCFullYear() Returns the year in the specified date, in universal <value expr="now.getUTCFullYear()"/>
time.
getUTCHours() Returns the hour in the specified date, in universal <value expr="now.getUTCHours()"/>
time.
getUTCMilliseconds() Returns the milliseconds in the specified date, in <value expr="now.getUTCMilliseconds()"/>
universal time.
getUTCMinutes() Returns the minutes in the specified date, in <value expr="now.getUTCMinutes()"/>
universal time.
getUTCMonth() Returns the month in the specified date, in universal <value expr="now.getUTCMonth()"/>
time.
getUTCSeconds() Returns the seconds in the specified date, in <value expr="now.getUTCSeconds()"/>
universal time.
setDate() Sets the day of the month for a specified date, in <var name="day" expr="now.setDate(22)"/>
local time.
setFullYear() Sets the year for a specified date, in local time. <var name="year" expr="now.setFullYear(2004)"/>
setHours() Sets the hours for a specified date, in local time. <var name="hours" expr="now.setHours(11)"/>
setMilliseconds Set the milliseconds for a specified date, in local <var name="ms" expr="now.setMilliseconds(22)"/>
time.
setMinutes() Sets the minutes for a specified date, in local time. <var name="min" expr="now.setMinutes(15)"/>
setMonth() Sets the month for a specified date, in local time. <var name="month" expr="now.setMonth(11)"/>

JAVASCRIPT QUICK REFERENCE 14


Standard Objects

Property/Method Description Example


setSeconds() Sets the seconds for a specified date, in local time. <var name="sec" expr="now.setSeconds(55)"/>
setTime() Sets the value of a Date object. <var name="time"
expr="now.setTime((new Date()).getTime())"/>
setUTCDate() Sets the day of the month for a specified date, in <var name="uday" expr="now.setUTCDate(22)"/>
universal time.
setUTCFullYear() Sets the year for a specified date, in universal time. <var name="uyear"
expr="now.setUTCFullYear(2004)"/>
setUTCHours() Sets the hours for a specified date, in universal time. <var name="uhours" expr="now.setUTCHours(11)"/>
setUTCMilliseconds() Set the milliseconds for a specified date, in universal <var name="ums"
time. expr="now.setUTCMilliseconds(222)"/>
setUTCMinutes() Set the minutes for a specified date, in universal <var name="umin" expr="now.setUTCMinutes(15)"/>
time.
setUTCMonth() Sets the month for a specified date, in universal <var name="umonth" expr="now.setUTCMonth(11)"/>
time.
setUTCSeconds() Sets the seconds for a specified date, in universal <var name="usec" expr="now.setUTCSeconds(55)"/>
time.
toString() Returns a string representing the entire date in the <value expr="now.toString()"/>
current time zone in a human-readable form.
toDateString() Returns a string representing the Date portion of the <value expr="now.toDateString()"/>
specified date in the current time zone in a
human-readable form.
toTimeString() Returns a string representing the Time portion of the <value expr="now.toTimeString()"/>
specified date in the current time zone in a
human-readable form.
toLocaleString() Returns a string representing the entire date in the <value expr="now.toLocaleString()"/>
current time zone in a human-readable form
according to locale conventions.
toLocaleDateString() Returns a string representing the Date portion of the <value expr="now.toLocaleDateString()"/>
specified date in the current time zone in a
human-readable form according to locale
conventions.

15 JAVASCRIPT QUICK REFERENCE


JAVASCRIPT QUICK REFERENCE

Property/Method Description Example


toLocaleTimeString() Returns a string representing the Time portion of the <value expr="now.toLocaleTimeString()"/>
specified date in the current time zone in a
human-readable form according to locale
conventions.
toUTCString() Returns a string representing the entire date in <value expr="now.toUTCString()"/>
universal time in a human-readable form.

Error

Property/Method Description Example


name Name of the error type. One of: <value expr="errorGenerator().name"/>
• Error
• EvalError
• RangeError
• ReferenceError
• SyntaxError
• TypeError
• URIError
message String describing the error. <value expr="errorGenerator().message"/>

Function

Property Description Example


length The typical number of arguments to the function. <script>
Read only. var multFun = new Function("x", "y", "return x * y")
</script>
<value expr="multFun.length"/>

Math

Property/Method Description Example


E e, approximately 2.718. Read only. <value expr="Math.E"/>
LN10 ln(10), approximately 2.302. Read only. <value expr="Math.LN10"/>
LN2 ln(2), approximately 0.693. Read only. <value expr="Math.LN2"/>
LOG10E log10(e), approximately 0.434. Read only. <value expr="Math.LOG10E"/>
LOG2E log2(e), approximately 1.442. Read only. <value expr="Math.LOG2E"/>

JAVASCRIPT QUICK REFERENCE 16


Standard Objects

Property/Method Description Example


PI pi, approximately 3.14159. Read only. <value expr="Math.PI"/>
SQRT1_2 square root of 2 over 2, approximately 0.707. Read only. <value expr="Math.SQRT1_2"/>
SQRT2 square root of 2, approximately 1.414. Read only. <value expr="Math.SQRT2"/>
abs() Absolute value. <value expr="Math.abs(-5)"/>
acos() Arc cosine. <value expr="Math.acos(1.0)"/>
asin() Arc sine. <value expr="Math.asin(1.0)"/>
atan() Arc tangent. <value expr="Math.atan(1.0)"/>
atan2() Arc tangent of a quotient. <value expr="Math.atan2(1.0,0.0)"/>
ceil() Ceiling, the smallest integer >= a number. <value expr="Math.ceil(1.5)"/>
cos() Cosine. <value expr="Math.cos(Math.PI)"/>
exp() e to the n power. <value expr="Math.exp(2.0)"/>
floor() Floor, the largest integer <= a number. <value expr="Math.floor(1.5)"/>
log() Natural log (base e). <value expr="Math.log(Math.E)"/>
max() Maximum. <value expr="Math.max(1.0,2.0)"/>
min() Minimum. <value expr="Math.min(1.0,2.0)"/>
pow() Power, a to the b power. <value expr="Math.pow(10.0,2.0)"/>
random() Random number between 0.0 and 1.0. <value expr="Math.random()"/>
round() Round. <value expr="Math.round(2.3)"/>
sin() Sine. <value expr="Math.sin(Math.PI)"/>
sqrt() Square root. <value expr="Math.sqrt(2.0)"/>
tan() Tangent. <value expr="Math.tan(Math.PI/4.0)"/>

Number

Property/Method Description Example


MAX_VALUE The largest representable number. Read only. <value expr="Number.MAX_VALUE"/>
MIN_VALUE The smallest representable number. Read only. <value expr="Number.MIN_VALUE"/>
NaN Not a number. Read only. <value expr="Number.NaN"/>
NEGATIVE_INFINITY Infinity (overflow). Read only. <value expr="Number.NEGATIVE_INFINITY"/>
POSITIVE_INFINITY Infinity (overflow). Read only. <value expr="Number.POSITIVE_INFINITY"/>
toFixed() Returns a string containing the number in fixed-point <value expr="Math.PI.toFixed(3)"/>
notation (with N digits after the decimal point).

17 JAVASCRIPT QUICK REFERENCE


JAVASCRIPT QUICK REFERENCE

Property/Method Description Example


toExponential() Returns a string containing the number in <value expr="Math.PI.toExponential(3)"/>
exponential notation (with 1 digit before the decimal
point and N after) .
toPrecision() Returns a string containing the number either in <value expr="Math.PI.toPrecision(3)"/>
exponential notation (with 1 digit before the decimal
point and N-1 after) or fixed-point notation (with N
significant digits).

RegExp

Property/Method Description Example


global Whether to test for all occurrences. Read only. <script>
<![CDATA[
var re4 = /d(b+)(d)/ig;
var s3 = new String("cdbBdbsbz");
var result4 = re4.exec(s3);
]]>
</script>
<value expr="re4.global"/>
ignoreCase Whether to ignore case, when doing comparisons. Read <value expr="re4.ignoreCase"/>
only.
input The input string. Static. <value expr="result4.input"/>
lastIndex The index at which to start the next match. Read/write. <value expr="re4.lastIndex"/>
lastMatch The last characters matched. Read only. <value expr="RegExp.lastMatch"/>
lastParen The last parenthesized match. Read only. <value expr="RegExp.lastParen"/>
leftContext The substring preceding the match. Read only. <value expr="RegExp.leftContext"/>
rightContext The substring following the match. Read only. <value expr="RegExp.rightContext"/>
source The match pattern. Read only. <value expr="re4.source"/>
compile() Compiles a regular expression. <script>
<![CDATA[
var re5 = /d(b+)(d)/gi;
re5.compile("/d(b+)(d)","gi");
]]>
</script>

JAVASCRIPT QUICK REFERENCE 18


Standard Objects

Property/Method Description Example


exec() Execute a search. <script>
<![CDATA[
var re4 = /d(b+)(d)/ig;
var s3 = new String("cdbBdbsbz");
var result4 = re4.exec(s3);
]]>
</script>
test() Test for a match. <script>
<![CDATA[
var s1 = new String("Catfish");
var re1 = /Cat/;
]]>
</script>
<value expr="re1.test(s1)"/>

String
None of the string methods change the original string.

Property/Method Description Example


length The length of a string. Read only. <value expr="myString.length"/>
charAt() Returns the single character at a specified index. <value expr="myString.charAt(3)"/>
charCodeAt() Returns a number indicating the ISO-Latin-1 codeset value <value expr="myString.charCodeAt(3)"/>
at a specified index.
concat() Concatenates two strings, and returns the result. <value expr="myString.concat(myString2)"/>
indexOf() Returns the index within a string, for a given character. <value expr="myString.indexOf('g')"/>
lastIndexOf() Returns the index within a string, for the last occurrence of a <value expr="myString.lastIndexOf('g')"/>
given character.
match() Matches a regular expression against a string, returning the <value expr="myString.match('at').join()"/>
match array.
replace() Matches and then replaces, returning a new string with the <value expr="myString.replace('a','e')"/>
replacement.
search() Determines whether a match exists between a regular <value expr="myString.search('at')"/>
expression and a string, returning the index of the match.
slice() Extracts a substring of a given string, returning the <value expr="myString.slice(3,8)"/>
substring.
split() Splits a string into an array of strings, returning the array. <value expr="myString2.split(' ').join()"/>

19 JAVASCRIPT QUICK REFERENCE


JAVASCRIPT QUICK REFERENCE

Property/Method Description Example


substring() Extracts a substring of a string, given two indices. <value expr="myString2.substring(9,15)"/>
toLowerCase() Converts a string to lower case. <value expr="myString.toLowerCase()"/>
toUpperCase() Converts a string to upper case. <value expr="myString.toUpperCase()"/>

BeVocal Constants (Extensions)

Constant Description Example


bevocal.outboundrequestid For calls initiated using the Outbound Notification <value expr="bevocal.outboundrequestid"/>
Service, the Outbound Request ID associated with
the call. This value can be used to map specific
application invocations with the request used to
initiate the application.
bevocal.sessionid Provides a unique ID for each call. This value can <value expr="bevocal.sessionid"/>
be used to keep track of call-specific information in
the server-side component of your application if
cookies cannot be used for any reason.

BeVocal Objects (Extensions)

Any SOAP proxy object

Property/Method Description Example


_addHeader() Specifies an additional SOAP header for the SOAP service <script>
that the proxy object represents. ...
service._addHeader(
"http://www.bevocal.com/soap/headers/",
"platformServicesSessionID",
"ACB035CB-C307-472e-99BA-3D5B8468BB76");
...
</script>

JAVASCRIPT QUICK REFERENCE 20


BeVocal Objects (Extensions)

bevocal.soap

Property/Method Description Example


serviceFromWSDL() Creates an object to act as a <script>
proxy for one of the services <![CDATA[
described in the file. function getTemperatureFromZipCode(s) {
var service = bevocal.soap.serviceFromWSDL(
// WSDL
"http://www.xmethods.net/sd/2001/TemperatureService.wsdl",
// portName
"TemperaturePort",
// targetNamespace from definitions
"http://www.xmethods.net/sd/TemperatureService.wsdl",
// serviceName
"TemperatureService",
// endpoint (optional)
"http://services.xmethods.com:80/soap/servlet/rpcrouter"
);
var temp = service.getTemp(s);
return(temp);
}
]]>
</script>
serviceFromEndpoint( Create an object to act as a <script>
) proxy for the service. ...
bevocal.soap.serviceFromEndpoint(
"http://cafe.services.bevocal.com/CDRAccessService_v2/services
/CDRAccessService_v2", http://www.bevocal.com/soap/services,
CDRAccessService)
...
</script>
locateService() Uses the BeVocal SOAP No services are currently available through the BeVocal SOAP service registry.
service registry to locate a
standard BeVocal SOAP
service.

21 JAVASCRIPT QUICK REFERENCE


JAVASCRIPT QUICK REFERENCE

bevocal.soap.SoapException
<script>
...
try {
myService.callMethod("too", "many", "parameters");
}
catch (error if error.type == "bevocal.soap.SoapException") {
if (error.cause == bevocal.soap.SoapException.CALL_ERROR) {
// Probably passed the wrong number of arguments
}
}
</script>

bevocal.soap.SoapFault

Property/Method Description
type bevocal.soap.SoapFault.
faultString A message describing the reason for the exception.
faultCode A code describing the reason for the failure.
faultActor The serviceId passed to lookupService could not be found in the registry.
detailString A String representation of the detail element of the fault. The detail element is present whenever a fault is
caused by processing of the Body element.
details An object whose properties are the detail elements; that is, the immediate child elements of the detail element
in the fault element.
MUST_UNDERSTAND SOAP fault code: A child of the SOAP Header element that contained a mustUnderstand attribute equal to "1"
was not understood.
VERSION_MISMATCH SOAP fault code: The processor found an invalid namespace for the SOAP Envelope.
SERVER SOAP fault code: Processing of the call failed due to an error on the server. The failure was not directly related to
the contents of the message, and the message may succeed at a later point in time.
CLIENT SOAP fault code: Processing of the call failed due to the contents of the message. This failure code is returned
when a function is called with invalid parameters, bad data, and so on.

bevocal.soap.SoapFaultDetails

Property/Method Description
type bevocal.soap.FaultDetails
(String) String representation of the details elements.

JAVASCRIPT QUICK REFERENCE 22


BeVocal Objects (Extensions)

Property/Method Description
(Number) Number of detail elements represented by the FaultDetail object.
element id Given a property name that is the local name (without namespace) of one of the child elements of the details
element, the property value is the text contents of the child element.

23 JAVASCRIPT QUICK REFERENCE


JAVASCRIPT QUICK REFERENCE

JAVASCRIPT QUICK REFERENCE 24

Anda mungkin juga menyukai