MooTools 2: Prime
by kentaromiura
HTML
<script src="http://fakedarren.github.com/mootools-website/assets/mootools/mootools.js"></script>
JavaScript
(function(prime,type,array){
var Class = (function(){
/// <classy.js>
var Class = prime({
mutator: function(key, method){
var self = this;
switch(key){
case 'mixin':
switch(type(method)){
case 'function': this.implement(prime.create(method).prototype); break;
case 'array': array.forEach(method, function(v){ self.implement({'mixin':v}); }); break;
case 'object': this.implement(method); break;
}
break;
default:this.prototype[key] = method; break;
}
}
})
var classy = function(proto){
var isClass = function(o){
var result = false;
var parent = o.inherits;
while(parent){
if(parent.isClass) {result = true;break;}
parent = parent.inherits;
}
return result;
}
/*
var clone = function(o){
var obj = function (){};
obj.prototype = o;
return new obj();
};*/
//remove objs from prototype
var objs = {};
for(var obj in proto){
if(type(proto[obj])=='object'){
objs[obj] = proto[obj];
delete proto[obj];
}
}
/* old alias */
if(proto.Extends) {
proto.inherits = proto.Extends;
delete proto.Extends;
}
if(proto.Implements){
proto.mixin = proto.Implements;
delete proto.Implements;
}
if(proto.initialize){
proto.constructor = proto.initialize;
delete proto.initialize;
}
/* old alias */
if (!proto) proto = {}
if (!proto.inherits) {
proto.inherits = Class
}else{
if(!isClass(proto)){
throw new TypeError("this prime does not inherit an instance of Class");
}
}
...