jeudi 11 août 2016

What is the difference between assigning to exports vs. module?

Consider the following code, based on the "loose augmentation" module pattern described at http://ift.tt/135lixg

var FOO = (function(exports) {

  //What is the difference between this:
  exports.hello = "hello";
  return exports;

}(FOO || {}));

var FOO = (function(exports) {

  //And this:
  FOO.world = "world";
  return exports;

}(FOO || {}));

//When the result works either way:
alert(FOO.hello + " " + FOO.world);

In this example, why would one assign to exports vs. FOO when it works the same either way? What is the difference?

Aucun commentaire:

Enregistrer un commentaire