Overview of the Scripting Syntax

Developer Resources

Overview of the Scripting Syntax

The scripting in Kirix Strata™ uses standard JavaScript syntax, but extends this syntax with an additional class construction for defining classes. JavaScript's traditional syntax allows for rapid prototyping, while the extended class syntax allows applications to be developed with a more robust, object-oriented design.

You should already be familiar with standard JavaScript syntax, so the rest of this section will focus on the class syntax.

Classes are declared as follows:

// class declaration
class MyClass
{
}

Once a class is defined, it can be created with the new operator, like objects:

var a = new MyClass;

Classes may contain both functions as well as properties.  These functions and properties are limited to the context of the class, meaning that two classes may both have the same function name or variables without them clashing with each other.

When classes are created, a special function, called the constructor, is executed if it exists.  For the constructor function to be called, it must have the same name as the class:

class MyClass
{
// constructor function; note: same name as class
function MyClass()
{
// this function will be called when the class
// is created
}
}

Functions and variables are defined inside the class with standard syntax:

// class declaration
class MyClass
{
// function declaration
function myFunction()
{
}

// variable declaration
var myVar;
}

When a class is defined, it can be defined on the basis of another class, a process called class inheritance.  When a class inherits from, or extends, another class, it "gets" all of it's parents' functions and variables.  In Strata scripts, class inheritance is denoted by the "extends" keyword:

// class declaration
class ParentClass
{
var a = "parent member";
}

class ChildClass extends ParentClass
{
// called when child class is created
function ChildClass()
{
// will show "parent member"
alert(a);
}
}

var c = new ChildClass;

When a child class is created, it may need to be created with specific parameters.  If the parent class also requires specific parameters, these parameters can be passed to the parent using the "super" keyword:

// class declaration
class ParentClass
{
function ParentClass(input)
{
alert(input);
}
}

class ChildClass extends ParentClass
{
// called when child class is created
function ChildClass(input)
{
// calls the parent's constructor function, parentClass()
// and passes the input parameter to this function
super(input);
}
}

var c = new ChildClass("test");