Syntax

JOII brings class-based programming to JavaScript. In order to mimic this syntax as best as possible, JOII utilizes the native JavaScript object syntax for parameter- and class-body definitions.

Once JOII is loaded, three functions become available in the global namespace, Class, Interface and Enum. Class and Interface share the exact same syntax. Enum is described in the Enum section

var MyClass = Class('name', { /* parameters */ }, { /* body */ });
var MyInterface = Interface('name', { /* parameters */ }, { /* body */ });

JOII automatically detects the way the Class or Interface function is called and fills in the optional arguments for you when needed.

Body

One parameter is always required, which is the body. The body contains properties and methods of your class- or interface definition.

var MyClass = Class({
    // properties and methods ...
});

Parameters

When two arguments are specified when defining a Class or Interface, the first argument must contain parameters and the second the body.

var MyClass = Class({ extends: AnotherClass }, {
    // properties and methods ...
});

Name

A name is optional but required when used as a type in property declarations. When a name is defined, the parameters object is still optional. For more information about custom types, please check out the types section.

// This is OK
var MyClass = Class('MyClass', {
    // properties and methods ...
});

// This is also OK
var MyClass = Class('MyClass', { extends: AnotherClass }, {
    // properties and methods ...
});