Skip to content

voidlock/inheritance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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;
  }
});

Releases

No releases published

Packages

No packages published