How are modules stored in an IIFE accessible through dot notation?

How are modules stored in an IIFE accessible through dot notation?
0

#1

So I understand what IIFE’s are, and why you would use them to create modules (so you can store information in private variables that will be used by functions within the module, correct?), but what I’m not really understanding is how assiging the properties to a new object through dot notations works. In the code in the lesson it shows this:

let motionModule = (function () {
  return {
    glideMixin: function (obj) {
      obj.glide = function() {
        console.log("Gliding on the water");
      };
    },
    flyMixin: function(obj) {
      obj.fly = function() {
        console.log("Flying, wooosh!");
      };
    }
  }
}) ();

being assigned by this:

motionModule.glideMixin(duck);
duck.glide();

Does the IFFE part just get skipped over? I understand that the function returns an object containing the mixins, but it seems like, to me at least, the fact that there is a function that returns the property into motionModule makes it different than if the property was just stored in an object called motionModule. I very well might be overthinking this, and it might be something I just need to accept works, but if anybody could shed some light onto this it would be great. Thanks!


#2

It doesn’t matter if you put it into an object instead of a function returning an object. These are two different javascript patterns so doing the same thing with two different approaches.

You can search more on javascript design patterns on google.
Mean while I will also refer you to this link.