Siebel eScript Language Reference > Siebel eScript Language Overview > Data Types in Siebel eScript >

Composite Data Types in Siebel eScript


Although primitive data types are passed by value, composite types are passed by reference. If a parameter is passed by reference, the variable's value may be changed for the calling procedure. When a composite type is assigned to a variable or passed to a parameter, only a reference that points to its data is passed, as in the following fragment:

var AnObj = new Object;
AnObj.name = "Joe";
AnObj.old = ReturnName(AnObj)

function ReturnName(CurObj)
{
return CurObj.name
}

After the object AnObj is created, the string "Joe" is assigned to the property AnObj.name. The string is assigned by value because a property is a variable within an object. Two copies of the string "Joe" exist.

When AnObj is passed to the function ReturnName(), it is passed by reference. CurObj receives a reference to the object, but does not receive a copy of the object.

With this reference, CurObj can access every property and method of AnObj, which was passed to it. If CurObj.name were to be changed while the function was executing, then AnObj.name would be changed at the same time. When AnObj.old receives the return from the function, the return is assigned by value, and a copy of the string "Joe" is transferred to the property.

Thus, AnObj holds two copies of the string "Joe": one in the property .name and one in the .old property. Three total copies of "Joe" exist, including the original string literal.

Two commonly used composite data types are Object and Array.

Object

An object is a compound data type that consists of one or more pieces of data of any type grouped together in an object. Data that are part of an object are called properties of the object.

The object data type is similar to the object data type in Visual Basic and the structure data type in C. The object data type also allows functions, called methods, to be used as object properties.

In Siebel eScript, functions are considered as variables. It is best to think of objects as having methods, which are functions, and properties, which are variables and constants.

Array

An array is a series of data stored in a variable that is accessed using index numbers that indicate particular data. The following fragments illustrate the storage of the data in separate variables or in one array variable:

var Test0 = "one";
var Test1 = "two";
var Test2 = "three";

var Test = new Array;
Test[0] = "one";
Test[1] = "two";
Test[2] = "three";

After either fragment is executed, the three strings are stored for later use. In the first fragment, three separate variables contain the three separate strings. These variables must be used separately.

In the second fragment, one variable holds the three strings. This array variable can be used as one unit, and the strings can also be accessed individually, by specifying the array subscript of the element containing the string to be used.

Arrays and objects use grouping similarly. Both are objects in Siebel eScript, but they have different notations for accessing properties. While arrays use subscripts, objects use property names or methods. In practice, arrays should be regarded as a unique data type.

Arrays and their characteristics are discussed more fully in Array Objects.

Siebel eScript Language Reference