Skip to content

Instantly share code, notes, and snippets.

@k33g
Created November 24, 2010 07:45
Show Gist options
  • Save k33g/713285 to your computer and use it in GitHub Desktop.
Save k33g/713285 to your computer and use it in GitHub Desktop.
mummy.js / Library for https://gist.github.com/713280
(function (){
/*mummy*/
var mum = {
select:function(child){
var thatChild = child;
return {
extends : function(parent){
var instance = new parent;
instance.constructor = thatChild.constructor;
instance.getTypeName = function(){return instance.constructor.name;}
instance.parent = new parent;
return instance;
},
implements : function(arrayOfInterfaces){
thatChild.interfaces = arrayOfInterfaces;
},
new : function(){
var instance = new thatChild;
//interfaces
if(instance.interfaces!=undefined){
//console.log('--- INTERFACES---');
for(var i=0; i < instance.interfaces.length; i++){
var instInterface = new instance.interfaces[i];
//console.log(instInterface.constructor.name);
for(var member in instInterface){
//console.log(member);
//console.log(instance[member]+' '+typeof(instance[member])+' '+typeof(instInterface[member]));
if(instance[member]!=undefined){
/* member exists */
if(typeof(instance[member])!=typeof(instInterface[member])){
throw member +' from '+instInterface.constructor.name+ ' is implemented in '+
instance.constructor.name +
' but '+typeof(instInterface[member])+
' expected instead of '+typeof(instance[member]);
}
}else{
throw member +' from '+instInterface.constructor.name+ ' is not implemented in '+ instance.constructor.name;
}
}
}
//console.log('--- END INTERFACES---');
}
instance.getTypeName = function(){return instance.constructor.name;}
instance['ctor'].apply(instance,arguments);
return instance;
}/*end of new*/
}/*end of return*/
}/*end of select*/
}
/*
var def = {
types:new Array(),
interfacesTypes:new Array(),
class:function(cl){def.types[(new cl).constructor.name]=cl;},
interface:function(interf){def.types[(new interf).constructor.name]=interf;}
}
*/
if(!window.$){window.$=mum.select;}
//if(!window.$def){window.$def=def;}
//if(!window.$t){window.$t=def.types;}
//if(!window.$i){window.$i=def.interfaceTypes;}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment