Tell us what’s happening:
I’m struggling understanding a detail in function declaration. The code example given to us here is:
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!");
};
}
}
}) (); // The two parentheses cause the function to be immediately invoked
I don’t really understand why the difference in syntax betwen the first ( function () {})(); , with a space after function, and the next one with no space: obj.glide = function() {};
I tried the IIFE with both space or no space, and it’s working. Is there a difference between those two, is there one I should use over the other?
Thanks!
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/use-an-iife-to-create-a-module