Skip to content

Instantly share code, notes, and snippets.

@naf03
Last active April 9, 2019 10:09
Show Gist options
  • Save naf03/0951ad6c040656fec9b096a85217e299 to your computer and use it in GitHub Desktop.
Save naf03/0951ad6c040656fec9b096a85217e299 to your computer and use it in GitHub Desktop.
librarySystem with dependencies
(function(){
var libraryStorage = {};
function librarySystem(libraryName, dependencies,callback){
if (arguments.length===1){
return libraryStorage[libraryName];
} else if (arguments.length>1){
if (dependencies.length===0){
libraryStorage[libraryName]=callback();
} else {
var dependentLibraries = dependencies.map(function(dependency){
return libraryStorage[dependency];
});
libraryStorage[libraryName]=callback.apply(null, dependentLibraries);
}
}
}
window.librarySystem=librarySystem;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment