Object Oriented Programming: Use an IIFE to Create a Module

let funModule = (function(){
  return {
  isCuteMixin :function(obj) {
  obj.isCute = function() {
    return "cute";
  };
},
  
  singMixin : function(obj) {
  obj.sing = function() {
   console.log("Singing to an awesome tune");
  };
}
}
})();
funModule.isCuteMixin(music);
console.log(music.isCute());
funModule.singMixin(music);
console.log(music.sing());

pls can anyone help check what’s wrong with this code on the exercise: Object Oriented Programming: Use an IIFE to Create a Module.
It says music not defined and didn’t pass it. i need help for i thought i followed the lesson correctly

If you haven’t defined music, then I would suggest to delete these lines:

funModule.isCuteMixin(music);
console.log(music.isCute());
funModule.singMixin(music);
console.log(music.sing());
1 Like

Have you created a music object? You are calling the music variable, which you are showing should be an object, but you haven’t initialized one.

To initialize? i was closely following the lesson and trying to understand the topic. but in the example there wasn’t anything like initializing. pls how do i go about it?
I seem to be confused! pls.

So, as @snigo has said, if you haven’t defined music, delete those four lines.

The lesson isn’t asking you to use the mixin module you’re creating, simply to create it. But, if you wanted to try using your mixin, then you’re doing it exactly right - call that mixin name, and pass in the object you want to attach the mixin to:

funModule.isCuteMixin(music);
console.log(music.isCute() );

Before that mixin call, the music class would likely not have had that method attached. The whole point of the mixin module is to allow you to attach common functionality to other objects, by keeping them in a common “mixin” module.

The issue here is, you haven’t created an object called music. Try this before those last four lines:

// let's create a music object
const music = {
  name: "Music music music!",
  play: function(){
    console.log("I am playing, lalalala!")
  }
}

// Now, we can use the funModule mixin functions to attach functionality
//   to the music object! Yaaay!

That simply creates an object, and we can pass that object into our mixins to add some functionality.

Thanks for the comprehensive explanation. I do really understand now. Once again thanks for being there for me!

1 Like

Always a pleasure, @Slomon80 - you’re doing great! Keep on plugging, and asking, and growing your knowledge. :wink:

Pieces of advice such as this motivates me leaving me with the drive that i will be there some day- becoming a real programmer. Thanks a million