What is JOII?

JOII (short for JavaScript Object Inheritance Implementation) brings class- based programming to JavaScript without the use of a compiler. Everything is done using native JavaScript. JOII allows you to build your applications using Classes and Interfaces as you would in most other object oriented languages. JOII is built with the priciple of being compatible with any browser on the market. Therefore, JOII is supported by Internet Explorer 5.5 and anything that came after that.



Like most other popular JavaScript libraries, JOII is released under the MIT license.

The MIT License is simple and easy to understand and it places almost no restrictions on what you can do with a JOII project. You are free to use any JOII-project in any other project (even commercial projects) as long as the copyright header is left intact. All sample codes on this website are public domain, meaning you're free to do with them as you please.

Sneak peek

This is an example of what JOII looks like in action.

// Define a simple class called "Person".
var Person = Class({

    // Declare a property called 'name'.
    'public immutable string name' : null,

    // Declare a constructor to be executed upon instantiation.
    'private __construct(string)': function (name) {
        this.name = name;

// Define a class called "Employee" that extends on "Person"
var Employee = Class({ extends: Person }, {

    // Add an 'occupation' property.
    'public nullable string occupation' : null,

    // Override the constructor from "Person".
    'private __construct(string)' : function (name) {
        // invoke the parent constructor
        this.super('__construct', name);

        // Set the given occupation.
    // Overload the constructor, to take an extra parameter.
    'private __construct(string, string)' : function (name, occupation) {
        // invoke the parent constructor
        this.super('__construct', name);

        // Set the given occupation.

var bob = new Employee('Bob');

console.log(bob.getName()); // Bob
console.log(bob.getOccupation()); // Developer

As you can see, the example code uses setter and getter methods that we didn't define. When a property is declared public, JOII automatically generates getters and setters for this property and enforces type checking in them.

Properties are not exposed to the public, even if they are declared to be.

// properties are never exposed to the public, this is undefined:

// This will throw an exception, because occupation must be a string:

When a property is declared protected, getters and setters are still generated but are not exposed to the public. When a property is declared private, nothing is generated.

Find out more about this in the getters and setters section.