Skip to content

Instantly share code, notes, and snippets.

@gordonmzhu
Forked from michael-mafi/libSys.js
Last active February 7, 2017 03:01
Show Gist options
  • Save gordonmzhu/a912e28cb4a717188a0ed5e275715f95 to your computer and use it in GitHub Desktop.
Save gordonmzhu/a912e28cb4a717188a0ed5e275715f95 to your computer and use it in GitHub Desktop.
library loading system
var libs = {};
function librarySystem(libName, depArr, cb){
if (arguments.length > 1 && depArr.length >= 1){
var storArr = [];
for(var i = 0; i < depArr.length; i++){
storArr.push(libs[depArr[i]]);
}
libs[libName] = cb.apply(this, storArr);
} else {
libs[libName] = cb();
}
return libs[libName];
}
/*
libs = {one:'one',two:'get',three:'boogie'};
libSys('dancelikenooneswatching', ['two', 'three'], function(name, company) {
return name + ' down and ' + company;
});
"get down and boogie"
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment