I'm trying to wrap my head around the nuances between the IIFE and the Immediately Invoked Constructor Function in Javascript.
From what I can gather from the code below, both functions act like anonymous functions in the sense that they cannot be called more than once. The only difference is that they are both called immediately, hence the term "immediately invoked." But I don't understand why you would use an Immediately Invoked Constructor Function, since I thought the whole point of a constructor function was to make reusable code for initializing objects? Especially since I'm under the impression I can write an IIFE to do the same thing as the Immediately Invoked Constructor Function... am I on the right track here... or am I completely off?
Immediately Invoked Function Expression.
(function(userName){
this.name = userName;
this.hasBuildingRights = false;
})("Bob the Builder");
Immediately Invoked Constructor Function.
let user = new function(userName){
this.name = userName;
this.hasBuildingRights = false;
};
Thanks for helping me understand in advance!