JavaScript utility belt for rich objects and prototypes. Ooooh!


If you like the rich OO features of other languages, such as Perl and Java, and wish you had the same power in JavaScript, 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 o.Class documentation.


Traits are created with new o.Trait(...) which creates a new Trait object. Traits can be included in classes or installed directly on to 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 o.Trait documentation.


Attribute 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 o.Attribute documentation.


Type objects validate and coerce attribute arguments. New types can be created via new o.Type(...) and used in attribute definitions.

var ageType = new o.AllType([

Read more in the Types and o.Type 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.