JavaScript utility belt for rich objects and prototypes. Ooooh!


If you like rich trait/mixin systems, expressive types, and complex object attributes provided by other languages (such as Perl, Python, and Ruby to name a few), but with a small footprint, then o.js is for you.


o.js is designed to extend JavaScript's native prototype system, not replace it. This means that o.js classes, traits, attributes, types, and objects are automatically compatible with existing JavaScript libraries.


o.js is built of components that do one thing and do it well, providing a rich library of utilities that build upon each other. Any layer of the o.js stack of components may be used independently as needed.



o.js may be freely distributed under the MIT license.


Define classes using new o.Class(...) which creates a standard JavaScript function constructor. A class can have attributes, methods, method overrides, and a number of other features. A class, at its core (take a look at the source code) is a very simple wrapper around a trait.

var Person = new o.Class({
    attributes: {
        name: { type:o.nonEmptyStringType },
        age: { type:o.integerType }
    methods: {
        log_name: function () {
            console.log( this.name );
var baggins = new Person({
    name: 'Bilbo',
    age: 111

Read more in the Classes documentation.


Traits are created with new o.Trait(...) which creates a new Trait object. Traits can be included in classes or installed directly onto existing objects.

var productTrait = new o.Trait({
    attributes: {
        price: { type:o.numberType }
var Sheet = new o.Class({
    attributes: {
        threadCount: { type:o.integerType }
    traits: [ productTrait ]
var mySheet = new Sheet({
    price: 24.95,
    threadCount: 160

Read more in the Traits documentation.


Attributes can be created directly via new o.Attribute(...) and re-used, or indirectly in class and trait definitions.

var fullNameAttr = new o.Attribute({
    type: o.nonEmptyStringType,
    required: true

Read more in the Attributes documentation.


Type objects validate and coerce attribute arguments. A library of pre-built types are included and new types may be created via new o.Type(...).

var ageType = new o.AllType([

Read more in the Types documentation.


A rich array of plumbing functions exist which provide the moving pieces that make classes, traits, attributes, and types work. Plumbing functions include o.construct(), o.augment(), o.merge(), o.clone(), o.has(), o.before(), o.after(), o.around(), etc.

Read more in the Plumbing documentation.