Last active
January 6, 2017 09:14
-
-
Save hanihsdd/827414219d32bb7180d7c0ba319c5318 to your computer and use it in GitHub Desktop.
Beast Challenge 2 – 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) { | |
if (dependencies.length > 0) { | |
var dependenciesExistArray = dependencies.map(function(dependency) { | |
return libraryStorage[dependency]; | |
}); | |
} | |
// `.apply` allows arguments to be provided as an array to our callback | |
libraryStorage[libraryName] = callback.apply(this, dependenciesExistArray); | |
} else { | |
return libraryStorage[libraryName]; | |
} | |
} | |
window.librarySystem = librarySystem; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment