Open omamazainab opened 3 years ago
Since the default values were set for the factory method i.e, Car constructor, if user did not pass any arguments at all i.e,
var carFactory = new VehicleFactory(); var car = carFactory.createVehicle();
it should create a Car object with default values. which would result in this object
Car { doors: 6, state: 'brand new', color: 'yellow' }
but instead it throws an error because if nothing is passed options will be undefined.
undefined
we set the default value of options to an empty object. It will then allow assigning all of the default values
options
Expected Behaviour
Since the default values were set for the factory method i.e, Car constructor, if user did not pass any arguments at all i.e,
it should create a Car object with default values. which would result in this object
Car { doors: 6, state: 'brand new', color: 'yellow' }
but instead it throws an error because if nothing is passed options will be
undefined
.Correction
we set the default value of
options
to an empty object. It will then allow assigning all of the default values