Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- // this is the "global" store. the function below has access to it because of closure
- var store = {}
- function librarySystem(name, dependencies, libraryCallback) {
- if(arguments.length < 2) {
- return store[name];
- } else {
- if(dependencies.length > 0) {
- // map the returned dependency to the passed in string array
- dependencies = dependencies.map(function(library) {
- if(Array.isArray(library)) {
- librarySystem(name, library, libraryCallback)
- } else {
- return store[library];
- }
- })
- // run the callback with passed in libraries
- store[name] = libraryCallback.apply(this, dependencies);
- } else {
- store[name] = libraryCallback();
- }
- }
- }
- window.librarySystem = librarySystem;
- })();
Add Comment
Please, Sign In to add comment