mercredi 11 mars 2015

Using global variables within module revealing pattern

Let's say that a global variable called "thirdParty" is loaded via a async JS file. As part of module revealing pattern (example below), how can I alter the code to make sure these IIFEs wait for "thirdParty" global variable to be available?



var app = app || {};
app.something = (function(){
function run() {
if(typeof thirdParty !== "undefined") {
// code within this function doesn't get executed as thirdParty is of type undefined at the time of this function execution
}
}
return {run:run};

})();

// function calls
jQuery(document).ready(function() {
app.something.run();
});

Aucun commentaire:

Enregistrer un commentaire