Skip to content

Instantly share code, notes, and snippets.

@michael-mafi
Last active February 7, 2017 02:57
Show Gist options
  • Save michael-mafi/94bc6bd98463a8035105f26db9671a01 to your computer and use it in GitHub Desktop.
Save michael-mafi/94bc6bd98463a8035105f26db9671a01 to your computer and use it in GitHub Desktop.
library loading system
var libs = {};
var libSys = function(libName, depArr, cb){
if (libName.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