Ozone (o3) JavaScript Class Framework

1.0.3 · abandoned · verified Sun Apr 19

The `o3` package, also known as Ozone, is a JavaScript class framework designed to bring enhanced object-oriented programming capabilities to ES5 environments. Released as version 1.0.3, its last significant update was over five years ago, indicating it is no longer actively maintained and can be considered abandoned. It aimed to provide class-like inheritance and structure at a time when native ES6 classes were not widely supported, offering an alternative to transpilers like Babel or TypeScript for class definitions. The framework requires an ES5-compatible environment, specifically relying on `Object.create` and ES5 property enumeration features. Its primary differentiator was enabling robust class inheritance in older runtimes without needing a build step. Due to its age and the universal adoption of native ES6 classes, its utility in modern JavaScript development is minimal.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates defining a base class and an inheriting class using o3's `Class` and `extend` methods, showcasing object instantiation and method calls.

const o3 = require("o3");
const Class = o3.Class;

// Define a base class inheriting from Object
const BasePerson = Class(Object, {
    prototype: {
        // Constructor function
        constructor: function BasePerson(name) {
            this.name = name;
        },
        // A method
        sayHello: function() {
            console.log(`Hello, my name is ${this.name}.`);
        }
    }
});

// Define a derived class using the inherited extend method
const Employee = BasePerson.extend({
    prototype: {
        constructor: function Employee(name, position) {
            // Call the super constructor
            BasePerson.prototype.constructor.call(this, name);
            this.position = position;
        },
        // Override or add new methods
        sayHello: function() {
            console.log(`Hello, I'm ${this.name} and I'm a ${this.position}.`);
        },
        work: function() {
            console.log(`${this.name} is working.`);
        }
    }
});

const person = new BasePerson("Alice");
person.sayHello();

const employee = new Employee("Bob", "Software Engineer");
employee.sayHello();
employee.work();

view raw JSON →