Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //function to create multiple object instances
- const robotFactory = (model, mobile) => {
- return{
- model: model, //key name to be of the same name as the parameter
- mobile, //for shorthand, can leave out the parameter name since it's the same as the key name
- beep(){
- console.log('Beep Boop');
- }
- }
- }
- //create object out of factory function
- const tinCan = robotFactory('P-500', true);
- tinCan.beep();
Add Comment
Please, Sign In to add comment