Js.Class Ruby style javascript

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 OOP.


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

  1. Classes and modules with Ruby-compatible inheritance
  2. Subclassing and mixins
  3. Late-binding arguments-optional super calls to parent classes and mixins
  4. Singleton methods and eigenclasses
  5. included, extended and inherited hooks
  6. Method binding
  7. Ports of various standard Ruby modules, including Enumerable, Hash, Set, Observable, Comparable, Forwardable

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.

var Animal = new JS.Class({
        initialize: function(name) {
            this.name = name;
        },

        speak: function(things) {
            return 'My name is ' + this.name + ' and I like ' + things;
        }
    });

Download & example available at it’s official website

Leave a Reply