What if I want to give the property another name, for instance I want the property model to be modelType, is there a shorthand for this or I have to use the normal property declaration without the shorthand?
I was having trouble understanding the guts of what was passing through the robotFactory function and whether the arguments were targeting the key: or the :value. I also was uncertain why the key-value both take the argument variable. I attempted to create a new key-value pair using energySource: ‘Pig’. So two questions:
Why do we have both the key and value take the same variable as the argument?
Why doesn’t the argument ‘chicken’ in newRobot overwrite the key-value (energySource: ‘Pig’)?
I think I figured out that I was asking the wrong questions. The argument doesn’t know to target the key or the value in particular, it merely targets all instances of the undefined variable that was fed into the argument. And if I want ‘Pig’ to be overwritable I need to include it as a default value in the argument instead.
property value shorthand is a shortcut that we can use when the property and the parameter have the same name. It doesn’t make sense if they don’t have the same name - how can you define the property name differently to the parameter and expect JavaScript to understand that this property has a value of the differently-named parameter?
There’s something I don’t really understand. This lesson states that destructuring is a shortcut introduced in ES6 which simplifies assigning object properties to variables. However, it also states that property value shorthand is a destructuring technique! What does that even mean and how is property value shorthand related to destructuring?
// To check that the property value shorthand technique worked:
const newRobot = robotFactory(‘P-501’, false)
console.log(newRobot.model)
console.log(newRobot.mobile)
newRobot.beep();
I guess, that anything stated in the parentheses of console.log, which happens to be part of the beep() method will be just logged to the console, no matter what.
want to know the parameter in robotFactory function is always same as property name like in this model and mobile .
why it not excecute if I do model1 in place of model ?