Extend for Prototype allows you to use traditional single-class inheritance in your Java Script applications. It also gives you many advanced features such as runtime class modification, introspection and change.

It is designed to be free from the “super”-related problems in ExtendClass (only has “superInit()”) and ExtendClassFurther (has an unreliable/broken “SUPER” implementation).

The idea is to keep your class definitions exactly as they are (that is, with Class.create), but to allow inheritance, class naming, and other goodies without changing your existing code.

You can get the latest version as well as more information here


  // Classes can be declared directly when created
  var Geometry = Class.create({
    CLASSDEF:{ name:"Geometry" },
    initialize:function() {
       alert("A new " + this.getClass().className + " was created")
    }
  })

  var Polygon = Class.create({
    CLASSDEF:{ 
       name:  "Polygon",
       parent: Geometry
    },
    initialize:function() {
      // Equivalent of super()
      Polygon.parentClass.constructor().call(this)
      this.points = arguments
    }
  })

  // We can alternatively create the class first, and the assign the 
  // prototype
  var Rectangle = Class.create()
  Rectangle.prototype = {
    CLASSDEF:{ 
       name:  "Rectangle",
       parent: Polygon
    },
    initialize:function() {
      // Equivalent of super()
      if ( arguments.length != 4 ) throw new Error("4 points expected")
      Rectangle.parentClass.constructor().call(this)
      this.points = arguments
    }
  }
  // We MUST call update when not giving the proto directly
  Rectangle.update()

  var a = new Polygon()
  var b = new Rectangle(1,1,1,1)