-
-
Save gordonmzhu/a912e28cb4a717188a0ed5e275715f95 to your computer and use it in GitHub Desktop.
library loading system
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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