Last active
April 9, 2019 10:09
-
-
Save naf03/0951ad6c040656fec9b096a85217e299 to your computer and use it in GitHub Desktop.
librarySystem with dependencies
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(){ | |
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