Created
December 27, 2016 13:27
-
-
Save She-Codes/9776edf6a78f4fe1e59f3a7460ff10b9 to your computer and use it in GitHub Desktop.
Watch and Code librarySystem with dependencies
This file contains hidden or 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(library, dependencyArray, callback) { | |
var libraries = []; | |
if ( arguments.length > 1 ) { | |
// go through dependencyArray and get the actual libraries | |
dependencyArray.forEach(function(dependency) { | |
libraries.push(libraryStorage[dependency]); | |
}); | |
libraryStorage[library] = callback.apply(this, libraries); | |
} else { | |
return libraryStorage[library]; | |
} | |
} | |
window.librarySystem = librarySystem; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment