Member Reference Operators

Top  Previous  Next

Operators:  .  [ ]

Syntax:

object . member

object [ string ]

array [ expression ]

string [ expression ]

 

The expression object is converted to an object according to these rules:

 

Input Type

Result

Undefined

error

Null

error

Boolean

Boolean object

Number

Number object

String

String object

 

The result of the operator is the member of the object whose name is the identifier member (for .) or whose name is the string string (for []). If the object has no member of that name, the result is undefined. The CellScript Simulator may report a warning in this case, as this is likely a programming error.

 

Note that the Boolean object has no members and so will always give the result undefined.

 

[] Operator Used with Array or String

The expression is converted to Number if necessary, then truncated to integer. The integer is used as an index into the array or into the characters of the string, where the first element/character is at index zero. The result of the operator is the array element or string character code, or undefined if there is no element corresponding to that index. In the latter case, the CellScript Simulator may also report a warning, as this is likely a programming error.

 

In the case of String, this is a shorthand for string.charCodeAt(), and it cannot appear on the left-hand side of an assignment.

Examples

x = Math.PI;// returns 3.141593
x = Math["PI"];// returns 3.141593
x = Array(5, 10, 15)// create array
y = x[1];// y = 10
x[2] = 12;// array now [5,10,12]
x = "ABCD";// create string
y = x[2]// y = 0x43, code for "C"
x[1] = 0x41;// error, can't modify string