Class Object

class Class extends Object

A Class object represents a class definition; it contains static methods and properties.

Each class object is based on whatever class it extends, or Object if not specified. The global class object Object is based on Class.Prototype, which is based on Object.Prototype, so classes can inherit methods and properties from any of these base objects.

"Static" methods and properties are any methods and properties which are owned by the class object itself (and therefore do not apply to a specific instance), while methods and properties for instances of the class are owned by the class's Prototype.

"ClassObj" is used below as a placeholder for any class object, as "Class" is the Class class itself. Ordinarily, one refers to a class object by the name given in its class definition.

Table of Contents

Static Methods

Call

Creates a new Class object without a Prototype.

ClassObj := Class()
ClassObj := Class.Call()

[v2.1-alpha.3+]: Creates a new Class object based on BaseClass or Object.

ClassObj := Class(Name, BaseClass, Args*)
ClassObj := Class(BaseClass, Args*)
ClassObj := Class.Call(Name, BaseClass, Args*)
ClassObj := Class.Call(BaseClass, Args*)
Name

Type: String

If omitted, it defaults to "". Otherwise, specify the class name to assign to ClassObj.Prototype.__Class.

BaseClass

Type: Class

If omitted, it defaults to Object. Otherwise, specify the base class. ClassObj.Base is set to this, while ClassObj.Prototype.Base is set to BaseClass.Prototype.

Args*

If specified, any other parameters are passed to static __New, as in ClassObj.__New(Args*).

Note: This applies when literally calling "Class" itself, not when calling classes.

Class() or Class.Call() can be used to construct a new Class object based on Class.Prototype. However, this new object initially has no Call method as it is not a subclass of Object. It can become a subclass of Object by assigning to Base, or the Call method can be reimplemented or copied from another class. A Prototype must also be created and assigned to the class before it can be instantiated with the standard Call method.

[v2.1-alpha.3+]: Class() or Class.Call() can be called with parameters. For backward-compatibility, it behaves as described in the paragraph above when the parameter count is zero. Otherwise (even if a parameter is explicitly unset), a Prototype is created automatically based on BaseClass.Prototype. This enables scripts to create Prototype objects which are based on native types other than Object, such as Map and Array, at runtime.

One example use is to create a struct definition at runtime.

Methods

Call

Constructs a new instance of the class.

Obj := ClassObj(Params*)
Obj := ClassObj.Call(Params*)

This static method is typically inherited from the Object, Array or Map class. It performs the following functions:

Call can be overridden within a class definition by defining a static method, such as static Call(). This allows classes to modify or prevent the construction of new instances.

This is a static method in the sense that it belongs to a class (such as Object), but at the same time it is an instance method of the class object, which is an instance of Class. The class Class itself has a static Call method. In other words, Class() or Class.Call() can be called to create a new class object at runtime.

Properties

Prototype

Gets or sets the object on which all instances of the class are based.

Proto := ClassObj.Prototype
ClassObj.Prototype := Proto

By default, the class's Prototype contains all instance methods and dynamic properties defined within the class definition, and can be used to retrieve references to methods or property getters/setters or define new ones. The script can also define new value properties, which act as default property values for all instances.

A class's Prototype is normally based on the Prototype of its base class, so ClassObj.Prototype.base == ClassObj.base.Prototype.

Prototype is automatically defined as an own property of any class object created by a class definition.

[v2.1-alpha.28+]: For safety and efficiency, struct classes have a read-only Prototype.

ClassObj() and value is ClassObj require that the Prototype property is a value property owned directly by the class, unless it is a Struct class. Changing its value typically only affects these two operations and direct references to ClassObj.Prototype. Previously-created objects and objects constructed by other means are generally unaffected, but may no longer identify as instances of the class.

With some exceptions, built-in functions typically construct objects based on a known prototype and are thus unaffected by changes to the Prototype property.