Created
November 24, 2010 07:45
-
-
Save k33g/713285 to your computer and use it in GitHub Desktop.
mummy.js / Library for https://gist.github.com/713280
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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