Ozone (o3) JavaScript Class Framework
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
-
TypeError: Object.create is not a function
cause The JavaScript environment is not fully ES5 compatible and lacks the `Object.create` method, which `o3` relies on heavily for inheritance.fixUpgrade your JavaScript engine or ensure polyfills for ES5 features are loaded before initializing `o3`. However, the framework is not recommended for environments requiring extensive polyfilling. -
TypeError: Cannot read properties of undefined (reading 'Class')
cause The `o3` module was not successfully required or imported, meaning the `o3` object is `undefined` when attempting to access `o3.Class`.fixVerify that `require('o3')` is correctly resolving the package. Check your `node_modules` directory and ensure the package is installed. If using a bundler, confirm its configuration allows CommonJS imports. -
TypeError: (0 , _o3.Class) is not a function
cause Attempting to use ES Modules `import { Class } from 'o3';` syntax with `o3`, which is primarily a CommonJS module and does not expose `Class` via named ESM exports.fixUse CommonJS `require` syntax: `const { Class } = require('o3');` or `const o3 = require('o3'); const Class = o3.Class;`.
Warnings
- breaking The `o3` framework is strictly designed for ES5 compatible environments. It will not function correctly in older JavaScript engines (e.g., IE8 or below) lacking `Object.create` or full ES5 property enumeration support.
- deprecated The `o3` package is no longer actively maintained, with its last publish occurring over five years ago. Users should consider alternatives like native ES6+ classes or modern transpilers (e.g., Babel, TypeScript) which provide robust and actively supported class functionalities.
- gotcha The framework explicitly does not support Opera due to issues with its Karma test launcher at the time of development. While it might function, official compatibility is not guaranteed.
- gotcha When inheriting from native classes like `Error`, special care must be taken with the constructor and `Error.captureStackTrace` to ensure correct stack trace capturing and `this` context binding.
Install
-
npm install o3 -
yarn add o3 -
pnpm add o3
Imports
- o3
import o3 from 'o3';
const o3 = require("o3"); - Class
const Class = require("o3");const { Class } = require("o3"); - Class
import { Class } from 'o3';const Class = o3.Class; // after const o3 = require('o3');
Quickstart
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();