Dynamically Included Javascript And Dependencies
So, as a sort of exercise for myself, I'm writing a little async script loader utility (think require.js, head.js, yepnope.js), and have run across a little bit of a conundrum. Fir
Solution 1:
Commendable that you are taking on such an educational project.
However, you won't be able to pull it off quite the way you want to do it.
The good news is:
- No need to know what file you are in
- No need to mess with eval.
You actually have everything you need right there: A function reference.
A callback
, if you will.
A rough P-code for your using
function would be:
functionusing(modules, callback) {
var loadedModules = []
// This will be an ajax call to load things, several different ways to do it..
loadedModules[0] = loadModule(modules[0]);
loadedModules[1] = loadModule(modules[1]);
// Great, now we have all the modules// null = value for `this`
callback.apply(null, loadedModules);
}
Post a Comment for "Dynamically Included Javascript And Dependencies"