JS.Class is a library designed to facilitate object-oriented development in JavaScript. It implements Ruby’s core object, module and class system and some of its metaprogramming facilities, giving you a powerful base to build well-structured OO programs.

    var Event = new JS.Class({
        include: JS.Observable,

        fire: function(data) {
            this.notifyObservers('fire', data);
        }
    });

Features

JS.Class is designed to make JavaScript behave like Ruby in terms of its OOP structures. To this end, it provides the following features:

Its inheritance system supports late-bound super() calls to parent classes and modules, including calls from singleton methods. It has been designed to mimick Ruby as closely as possible, so if you know Ruby you should feel right at home.

Download version 2.1

Version 2.1 builds on the 2.0 core and libraries and adds several new core features and packages. A quick tour of the new features:

Download JS.Class 2.1.0

Most code based on version 1.x will be compatible with this release, but there a few issues to be aware of. If you have code you cannot update to 2.x at present, 1.6 is still available:

Download JS.Class 1.6.3

Acknowledgements

JS.Class was initially inspired by, and borrows ideas from, these open-source projects:

The standard library has been influenced by techniques demonstrated in Pro JavaScript Design Patterns, and contains ports of a few standard Ruby modules.

JS.Class is © 2007–2009 James Coglan. You can find update announcements via my blog. The source code is hosted on Github.