Keyword namespace is used to declare new namespaces. Namespace is a collection of functions, classes, variables, etc. aggregated in single unit. Namespaces can contain other (inner) namespaces too. “Under the hood” namespace is just a named global object. Keyword super can be used to access members of parent namespace that have the same name as in inner namespace.
Declaration of namespace:
Keyword class is used to define new classes (types of objects):
Where:
<function> is a standard function declaration. Such function can be used as an instance method or static method of the class.<constructor> is a function with predefined name this. <property> is a special type of member function. See more details below.<var> is a standard var declaration - allows to define class or module variables (a.k.a. static variables)<const> is a declaration of named constant.<type> is a declaration of inner type.Function with the name this being declared in context of some type will serve a role of constructor for all instances of the class.
Main goal of the constructor is to initialize instance of the class (a.k.a. object of the class) - create and initialize all fields the instance shall contain. Object that is being created is accessible through variable named this inside the constructor 1).
Compiler generates invocation of the constructor when it handles new operator:
// tor.one == 1 at this point
In any other aspect function this() is an ordinary function that may have any number of parameters defined including Optional parameters.
Function with any other name being declared in context of some type is known as a method of the class. If some method-function has a reference to the this variable then it is said that this function is an instance method. If the function does not refer to the this variable then it is a class method (a.k.a. static method).
Instance methods must be called in context of some object of the class:
// calling method Tor.rotate in context of // 'tor' instance.
Static method of some type a) does not refer to the this variable and/thus b) can be called by using Type.Method notation
// calling method Tor.rotateAll as a class method.
TIScript supports definition of computable properties - special functions that will be executed to set or get value of property. Syntax of computable property definition:
Body of the property can contain statements that can appear in normal function body as also special get and set sections. get section(s) will be executed conditionally when the function will be invoked for getting value of the property and set section for setting value of the property. Samples:
// single expression get block // single expression set block "second""get\n""set\n"
val.
It is possible to define so called Undefined Property Handler that allows to deal with undefined properties. Syntax of Undefined Property Handler is similar to the computable property handler but with 'undefined' used as its name:
Undefined Property Handler function has to have precisely two parameters: name of the property and its value that used in property set operation.
Undefined Property Handlers can be used in cases when set of properties is unknown upfront - in other words to support Virtual Properties. For example you may wish to access fields of recordset as properties
"SELECT firstName, secondName FROM employee"// redirect to rs.getFieldValue(#firstName); call // through property undefined()
Type variables (class static or namespace variables) are variables that are defined in context of some type using var keyword. Example:
// create variable that contains empty array; // create variable that contains object; // create variable that contains integer zero;To access such variables use their fully qualified names:
"anything"
Namespace constants (a.k.a. constants) are read-only variables that defined in context of some type using const keyword. Example:
To access such constants use their fully qualified names: