FAQ: Advanced Objects - Factory Functions


#1

This community-built FAQ covers the “Factory Functions” exercise from the lesson “Advanced Objects”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Web Development

Introduction To JavaScript

FAQs on the exercise Factory Functions

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

I think i’m missing the point of this exercise. I have it all working :

// step 1
const robotFactory = (model, mobile) => {
  return {
    model: 'model',
    mobile: 'mobile',
    beep() {
    	console.log('Beep Boop');
  	}
  }
};
// step 2
const tinCan = robotFactory('P-500', true);

// step 3
tinCan.beep();

The results spits out “Beep Boop”. My question is : Where are the (P-500, true) values from step 2.? What was I supposed to learn from this?


#3

I also don’t get what that “true” of the second argument in “step 2” is for.
I changed to “false” to test out, and tinCan.beep(); still works.


#4

If you poll their values, they will be found…

console.log(tinCan.model, tinCan.mobile, tinCan.beep());

#8

Hey, in this exercise it is asked of us to use const to declare the monster function, and i tried to use function out of curiosity, and it’s working.
Hence my question : is there any reason to use either one rather than the other ?


#9

Concerning the lesson (not the exercise), what happens to the “catchPhrase” parameter to “monsterFactory”?

catchPhrase is not a property of the monster object, but there seems to be a copy maintained somewhere because you can create two monster objects with different catchPhrases and the scare() method works as expected.

Thanks for any explanation you can supply!