Skip to content

Instantly share code, notes, and snippets.

@EmbraceLife
Created September 3, 2019 02:18
Show Gist options
  • Save EmbraceLife/be15bec729cbac3b96040ccade88aefb to your computer and use it in GitHub Desktop.
Save EmbraceLife/be15bec729cbac3b96040ccade88aefb to your computer and use it in GitHub Desktop.
runWithDebugger added dependencies
(function createLibrarySystems(){
var libraryStorage = {};
function librarySystem(libraryName, dependenciesArray, callback){
if (arguments.length > 1){
if (dependenciesArray.length > 0) {
var dependencyLibs = dependenciesArray.map(function(dep){
return libraryStorage[dep];
})
libraryStorage[libraryName] = callback.apply(this, dependencyLibs);
} else {
libraryStorage[libraryName] = callback();
}
} else {
return libraryStorage[libraryName];
}
}
// debugger;
// librarySystem('name', [], function() {
// return 'Gordon';
// });
// librarySystem('company', [], function() {
// return 'Watch and Code';
// });
// librarySystem('workBlurb', ['name', 'company'], function(name, company) {
// return name + ' works at ' + company;
// });
// librarySystem('workBlurb'); // 'Gordon works at Watch and Code'
window.myLibs = librarySystem;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment