Object Oriented Programming - Use an IIFE to Create a Module

Tell us what’s happening:
Describe your issue in detail here.
i wanted to know , i have seen in a lot of functions we can add parameter whatever we want , we can name it anything but we also before used to give a argument to it when we used to call the function , now i get confused when we add a parameter of like in the forward example we have created a obj parameter but i dont know how it is being worked inside the function now, can u explained this plz, a function with a parameter which is being used but has now argument .

Your code so far

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

also in this code we have name parameter can u explain this plz
const names = [‘poppy’, ‘wes’, ‘kait’, ‘snickers’, ‘lux’];

const kaitIndex = names.findIndex(name => name === ‘kait’);
console.log(kaitIndex);
console.log(names[kaitIndex]);
const newNamesWithoutKait = [
…names.slice(0, kaitIndex),
…names.slice(kaitIndex+1)
//…names.slice(3)
];
console.log(newNamesWithoutKait);
Your browser information:

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

Challenge: Object Oriented Programming - Use an IIFE to Create a Module

Link to the challenge:

You pass the object to the method when you call it as shown in the example. The duck object doesn’t exist in the example code but it is the object.

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

Array methods pass each element of the array it is looping to the first parameter of the callback function. name is the element in the names array for that given iteration.

[1, 2, 3, 4].forEach((number) => console.log(number)); // 1, 2, 3, 4

const names = [‘poppy’, ‘wes’, ‘kait’, ‘snickers’, ‘lux’];

const kaitIndex = names.findIndex(name => name === ‘kait’);
console.log(kaitIndex);
console.log(names[kaitIndex]);
const newNamesWithoutKait = [
…names.slice(0, kaitIndex),
…names.slice(kaitIndex+1)
//…names.slice(3)
];
console.log(newNamesWithoutKait);

can u explain this one plz we have name parameter how with name === ‘kait’ working ,
is it looping every name from names i mean every string?

Yes, that is the point of an array method. It loops the array for you and you get access to the elements inside the callback.

1 Like

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