1 array literals, 2 object literals, 3 complex literals – Casio Naurtech CETerm Ver.5.5 Scripting Guide User Manual
Page 23: Myarray[0] now has the value 2, Myobject.name now has the value „fred
N
AURTECH
W
EB
B
ROWSER AND
T
ERMINAL
E
MULATION FOR
W
INDOWS
CE
AND
W
INDOWS
M
OBILE
CETerm Scripting Guide
Page 23
2.8.1 Array Literals
Here is a simple JavaScript statement that uses an array literal to create an array
and assign it to a JavaScript variable:
var myArray = [ 2, 4, 6 ];
myArray[2] now has the value 6.
If a CETerm object returned the same array literal, then you would use the
JavaScript eval function to assign the array to a JavaScript variable:
var arrayResult = "[2, 4, 6]";
var myArray = eval( arrayResult );
myArray[0] now has the value 2.
2.8.2 Object Literals
Here is a simple JavaScript statement that uses an object literal to create an
object and assign it to a JavaScript variable:
var myObject = {name:'fred', attributes:0x21, size:12341234};
myObject.attributes has the value 0x21.
If a CETerm object returned the same object literal, then you would again use the
JavaScript eval function to assign the object to a JavaScript variable. Because
the curly-bracket operator may delimit either a block of statements or an object
literal, you must convert object literal strings in a slightly different way:
var objectResult = "{name:'fred', attributes:0x21, size:12341234}";
var myObject = eval( "(" + objectResult + ")" ); // note parenthesis
// or the preferred format
eval( "var myObject=" + objectResult );
myObject.name now has the value „fred‟.
2.8.3 Complex Literals
A complex literal may consist of nested array and object literals, but it is treated
in the same manner. In general you should use the eval syntax shown for the
object literal for all types of array, object, or complex literals.