JSX

a faster, safer, easier JavaScript
Powered by Oktavia

Primitive Types

JSX provides the following four primitive types. Primitive types are non-nullable.

Int (represents 32-bit signed integer) exists as a type, but variables (or properties or constants) of the type are generated only when the type is specified explicitly (i.e. var n = 1; defines a variable n of type number, var i : int = 1; defines a variable i of type int). This is due to the fact that the use of int may lead to slower execution speed.

Nullable Primitive Types

A nullable counterpart exists for each primitive type. Values of the types are returned by [] operators of Array.<primitive_type> and Map.<primitive_type>.

Variant Type

A variant can hold any type of data (including null). To use the data, explicit cast to other data types is necessary.

Built-in Object Types

Object

Object class is the root class for all objects.

Array.<T>

The class represents an array, by providing the [] operator that takes a number as the argument, length property and other methods to manipulate the array. In contrast to JavaScript, the array is typed. An instance of Array.<T> class may only store elements of type T or null.

The size of the array automatically grows. null is returned when an element out of the current boundary is requested.

There are two ways to create an array object; one is to use the new opreator, the other is to use the array initialiser. The type of the array returned by an array initialiser is deducted from the type of the elements. Type information should be annotated in cases where such deduction is impossible (such as when initializing an empty array).

new Array.<number>;         // creates an empty array of numbers
new Array.<number>(length); // creates an array of given length (elements are initialized to null)
[] : Array.<number>;        // creates an empty array of numbers
[ 1, 2, 3 ];                // creates an array of numbers with three elements: 1, 2, 3

Map.<T>

The class represents an associative array (collection of key-values pairs), mapping strings to values of type T or null.

Operator [] (that takes a string as the argument) is provided for registering / retreiving a keyed value. for..in statement can be used for iterating the keys. hasOwnProperty method is provided for checking whether or not a key-value pair of a particular name is registered. The delete statement can be used for unregistering a key-value pair.

Map objects can be created in two ways; by using the new operator or by using the map initialiser.

new Map.<number>;  // creates an empty map of strings to numbers
{} : Map.<number>; // same as above
{ a: 1 };          // creates a map of strings to numbers that has one pair: ("a" => 1)

Boolean, Number, String

Internal types used for applying methods against primitives.

These types of objects are instantiated when applying the dot operator against the primitives. For exmaple, the following code snippet applies the operator against string "abc", that returns a String object wrapping the primitive value. Then the charAt method of the object is called and "a" (of type string) is returned.

"abc".charAt(0) // returns "a"

Although being possible, it is discouraged to instantiate and store these values of the types (e.g. var s = new String("abc")). Use of the primitive types (or nullable primitive types) is preferable for performance and debugging reasons.

Number and String classes also provide some useful class methods and constants, e.g. Number.parseInt(:string):number, String.encodeURIComponent(:string):string.

JSX

The class provides some methods for controlling the runtime environment.

User-defined Types

Users may define a new class by extending the Object class, or by declaring an interface or a mixin. See Class, Interface and Mixin.