Object operators are used to create and reference objects, properties, and methods. Here are the Object operators:

Operator

Description 

NEW

Creates a new instance of an object 

[ ]

Index operator, which accesses the contents of an object through a numeric or string value 

. (period)

Dot operator, which accesses the contents of an object through an identifier name 

::

Scope resolution operator, to reference a method in a class or call a method from a class. 

NEW operator

The NEW operator creates an object or instance of a specified class.

The following is the syntax for the NEW operator:

[<object reference> =] new <class name>([<parameters>])

The <object reference> is a variable or property in which you want to store a reference to the newly created object.

Note that the reference is optional syntactically; you may create an object without storing a reference to it. For most classes, this results in the object being destroyed after the statement that created it is finished, since there are no references to it.

The following example shows how to use the NEW operator to create a Form object from the Form class. A reference to the object is assigned to the variable customerForm:

customerForm = new Form( )

This example creates and immediately uses a Date object. The object is discarded after the statement is complete:

? new Date( ).toGMTString( )

Index operator

The index operator, [ ], accesses an objectís properties or methods through a value, which is either a number or a character string. The following shows the syntax for using the index operator (often called the array index operator):

<object reference>[<exp>]

You typically use the index operator to reference elements of array objects, as shown in the following example:

aScores = new Array(20) // Create a new array object with 20 elements

aScores[1] = 10 // Change the value of the 1st element to 10

? aScores[1] // Displays 10 in results pane of Command window

Dot operator

The dot operator, ("."), accesses an objectís properties, events, or methods through a name. The following shows the syntax for using the dot operator:

<object reference>[.<object reference> ...].<property name>

Objects may be nested: the property of an object may contain a reference to another object, and so on. Therefore, a single property reference may include many dots.

The following statements demonstrate how you use the dot operator to assign values:

custForm = new Form( ) // Create a new form object

custForm.title = "Customers" // Set the title property of custForm

custForm.height = 14 // Set the height property of custForm

If an object contains another object, you can access the child objectís properties by building a path of object references leading to the property, as the following statements illustrate:

custForm.addButton = new Button(custForm) // Create a button in the custForm form

custForm.addButton.text = "Add" // Set the text property of addButton

Scope resolution operator

The scope resolution operator (::, two colons, no space between them) lets you reference methods directly from a class or call a method from a class.

The scope resolution operator uses the following syntax:

<class name>|class|super::<method name>

The operator must be preceded by either an explicit class name, the keyword CLASS or the keyword SUPER. CLASS and SUPER may be used only inside a class definition. CLASS refers to the class being defined and SUPER refers to the base class of the current class, if any.

<method name> is the method to be referenced or called.

Scope resolution searches for the named method, starting at the specified class and back through the classís ancestry. Because SUPER starts searching in a classís base class, it is used primarily when overriding methods.