JSX

a faster, safer, easier JavaScript
Powered by Oktavia

Class, Interface and Mixin

A class in JSX have following characteristics.

For example, class E extends A implements C, D means: C can override members of A (*1), D can override members of the production of *1 (*2), and that E can override members of the production of *2.

A class may have the attributes listed in Table 1.

Table 1. Class Attributes
NameDescription
abstract a class with abstract methods should have the attribute set
final declares that the class may not be extended

An user-defined class may have zero ore more functions or variables.

The example below defines a class called Human with a member variable _name, constructor function that takes a string as an argument, and a non-static member function (i.e. method) called say, that does not take any arguments and returns void).

class Human {
    var _name : string;
    function constructor(name : string) {
        this._name = name;
    }
    function say() : void {
        log "My name is " + this._name;
    }
}

Member Function

A member function is defined by either of the following form. Arguments should have their types being annotated. The default value may follow the type annotation, which will be evaluated in the function scope in runtime. The type after the closing parenthesis at the end of the argument list designates the return type of the function. Function that is not attributed abstract or native should have body. Function that is attributed abstract may have body.

// function with body
attribute* function funcname([arg1 : type [= defaultValue] [, arg2 : type, ...]]) : type { statement* }

// function without body
attribute* function funcname([arg1 : type[, arg2 : type, ...]]) : type;

A function may have the attributes listed in Table 2.

Table 2. Attributes of a Member Function
NameDescription
abstract declares that the function should be overridden by a class that extends the class
final declares that the function may not be overridden
static declares that the function is static
override declares that the definition of the function is overriding an definition in the extended class (or implemented interface or mixin). A function overriding an existing function should have the attribute set.

Member Variable

A member variable is defined in the following form. For ordinary variables, either the type or the expression should be specified. For constants, expression is mandatory and type is optional.

// ordinary variable
attribute* var varname [: type][ = expression];

// constant
static const CONSTNAME [: type] = expression;

An ordinary member variable may have the attributes listed in Table 3.

Table 3. Attributes of a Member Variable
NameDescription
abstract declares that the variable should be defined in a class that extends the class
static declares that the variable is static

Referring to Members

Member functions and variables can be referred to by applying the "." operator against a class name (for static members) or against a variable of the class type (or this).

// refers to a static variable
_Klass_.static_var

// calls a static function
_Klass_.static_func(...)

// refers to a non-static variable
_instance_.var
this.var // only within a non-static function

// calls a non-static function (i.e. method)
_instance_.func()
this.func() // only within a non-static function

Interface

An interface in JSX is similar to that of Java, except for the fact that it may have abstract variables. All the non-static functions are implicitly marked as abstract, and they cannot have bodies. An interface may implement other intefaces.

Mixin

Mixin is provided so that implementations can be shared between classes. Mixins may implement interfaces or other mixins. It may have functions with body or non-abstract variables.