Report abuse

Prototype 1.6.0: copy class methods from superclass


			
// add this before your class definitions
Class.Methods.inheritClassMethods = function() {
  var parent = this.superclass
  if (!parent) return

  for (prop in parent) {
    if (prop != 'superclass' && prop != 'subclasses' &&
        prop != 'constructor' && prop != 'prototype' && // exclude special properties
        !Class.Methods[prop] && // exclude Class instance methods
        parent[prop] !== Function.prototype[prop]) { // exclude Function instance methods
      this[prop] = parent[prop];
    }
  }
}

usage example


			
Animal.foo = function(){ ... }
var Cat = Class.create(Animal, { ... })

Cat.inheritClassMethods()
Cat.foo()