Skip to content

Instantly share code, notes, and snippets.

@hanihsdd
Last active January 6, 2017 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanihsdd/827414219d32bb7180d7c0ba319c5318 to your computer and use it in GitHub Desktop.
Save hanihsdd/827414219d32bb7180d7c0ba319c5318 to your computer and use it in GitHub Desktop.
Beast Challenge 2 – librarySystem with dependencies
(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