Table of Contents



Objects

Objects are Expr values that contain state and expose methods or properties.

Expr uses objects for collections, host integration, GUI controls, callbacks, and user-defined class instances.


Object Values

An object value is stored in a variable like any other value.

items = array(1, 2, 3);
lookup = map('x', 10);

Objects are usually used through methods.

items.add(4);
lookup.get('x');

Some objects also expose read-only properties.

lookup.x;

Property assignment is not supported. Use object methods to change object state.


Object Constructors

Built-in objects are usually created by built-in constructor functions.

items = array();
lookup = map();

User-defined objects are created by calling an Expr class constructor.

class Counter(start)
{
    value = start;
}
 
c = Counter(10);

Built-in constructor functions are listed in Built-in functions.


Object Methods

Object methods are called with dot syntax.

object.method(arguments);

The methods available depend on the object type.

Examples:

array(1, 2, 3).size();
map('x', 10).has('x');

General method call rules are described in Methods and properties.


Object Properties

Some objects expose properties that can be read with dot syntax.

object.property;

Property support is object-specific. If the property does not exist, Expr raises a runtime error.

Direct property assignment is not supported.

object.property = 10;     // not supported

Cloning and String Conversion

Some objects can be cloned with `clone()`.

a = array(1, 2, 3);
b = a.clone();

Objects also support `to_string()`.

array(1, 2, 3).to_string();
map('x', 10).to_string();

Whether `clone()` is supported depends on the object type.


Built-in and User-defined Objects

Built-in objects are implemented by Expr or the host application. See Built-in objects.

User-defined objects are created with Expr classes. See Classes and user-defined objects.

Previous: String Trim and Case Methods

Next: Built-in objects