voidlock / inheritance

Javascript OO Ruby Style

Home Page:http://code.google.com/p/inheritance/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inheritance.js

Inheritance.js is a plugin for the Prototype Javascript library that provides developers with a complete, unobtrusive, Ruby inspired, classical inheritance model. Using Inheritance.js, developers are given the power to easily define classes, sub-classes, and mix-ins, with a sprinkle of syntax sugar. The process of overriding methods is simplified; Inheritance.js uses a properly scoped parent method that is made available only inside an overriding method. To top it off, Inheritance.js accomplishes all this without adding any additional properties or methods to the developer's instantiated objects.

Person = Class.extend({
  // adding a mixin
  include: Sortable,

  // initializer function
  initialize: function(name) {
    this.name = name;
  },

  // ... methods ...

  toString: function() {
    return this.name;
  }
});

Employee = Class.extend(Person, {
  // adding mixins
  include: [Sortable, OtherModule],

  // initializer function
  initialize: function(name, dept) {
    // call parent function
    this.parent(name);

    // more initialization
    this.dept = dept;
  },

  // ... methods ...

  toString: function() {
    // call parent function
    return this.parent() + ' works in ' + this.dept;
  }
});

About

Javascript OO Ruby Style

http://code.google.com/p/inheritance/

License:Other


Languages

Language:JavaScript 87.1%Language:Ruby 12.9%