Guest User

Untitled

a guest
Oct 22nd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. (function() {
  2. // this is the "global" store. the function below has access to it because of closure
  3. var store = {}
  4.  
  5. function librarySystem(name, dependencies, libraryCallback) {
  6. if(arguments.length < 2) {
  7. return store[name];
  8. } else {
  9. if(dependencies.length > 0) {
  10. // map the returned dependency to the passed in string array
  11. dependencies = dependencies.map(function(library) {
  12. if(Array.isArray(library)) {
  13. librarySystem(name, library, libraryCallback)
  14. } else {
  15. return store[library];
  16. }
  17. })
  18. // run the callback with passed in libraries
  19. store[name] = libraryCallback.apply(this, dependencies);
  20. } else {
  21. store[name] = libraryCallback();
  22. }
  23. }
  24. }
  25. window.librarySystem = librarySystem;
  26. })();
Add Comment
Please, Sign In to add comment