What is the difference between returning an object from an iife and just creating an object

// is there any difference between funModule and notFunModule????
let funModule = (function () {
return {
  isCuteMixin: function(obj) {
    obj.isCute = function() {return true}
  },
  signMixin: function(obj) {
    obj.sing = function() {
      console.log("Singing to an awesome tune");
    }
  }
}
})()

let notFunModule = {
isCuteMixin: function(obj) {
  obj.isCute = function() {return true}
},
signMixin: function(obj) {
  obj.sing = function() {
    console.log("Singing to an awesome tune");
  }
}
}

let person = {};

notFunModule.isCuteMixin(person);
console.log(person)
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.75 Safari/537.36

Challenge: Use an IIFE to Create a Module

Link to the challenge:

Can you provide a bit more details about what you’re asking? I’m not sure what you mean.

im just asking if there is any difference between using a function to return an object and just creating the object myself because both ways seem to do the same thing and i wanted to know if there was any benefit of using a function

If your code is going to need to generate multiple objects based on the same pattern or logic, you would want to use a function to generate those objects.

For example, every time a new user joins this forum we don’t want a developer to have to manually add the user objects.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.