mercredi 19 août 2015

How to call/use this module in other JS files/modules

I read some JS module design patterns recently. I came across this small code snippet as below.

(function(window) {
    var Module = {
        data: "I'm happy now!"
    };

    window.Module = Module;
})(window);

Still not quite understand this code well, my questions are:

  • How to use/call this module outside this particluar JS file? Need I assign a variable to this module? e.g. var module1 = (...)(...);
  • Could anyone explain what the window parameter here stands for?
  • Is it a good practice to have two/three such kind of modules in the same file?

Aucun commentaire:

Enregistrer un commentaire