Extends a class onto itself with new property, preserving any items attached to the class's namespace.
Class.refactor = function(original, refactors){
Object.each(refactors, function(item, name){
var origin = original.prototype[name];
if (origin) origin = origin.$origin;
if (origin && typeof item == 'function'){
original.implement(name, function(){
var old = this.previous;
this.previous = origin;
var value = item.apply(this, arguments);
this.previous = old;
return value;
});
} else {
original.implement(name, item);
}
});
return original;
};