You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reading this right here, the Factory Pattern section.
// Our default vehicleClass is CarVehicleFactory.prototype.vehicleClass=Car;// Our Factory method for creating new Vehicle instancesVehicleFactory.prototype.createVehicle=function(options){switch(options.vehicleType){case"car":
this.vehicleClass=Car;break;case"truck":
this.vehicleClass=Truck;break;//defaults to VehicleFactory.prototype.vehicleClass (Car)}returnnewthis.vehicleClass(options);};
You say that this.vehicleClass defaults to Car, but in practice, the first time you do it it default to car but every other time it defaults to whatever class you instantiated last. Try making a truck and then a car:
// Create an instance of our factory that makes carsvarcarFactory=newVehicleFactory();vartruck=carFactory.createVehicle({vehicleType: "truck",color: "yellow",doors: 6});varcar=carFactory.createVehicle({color: "yellow",doors: 6});// Test to confirm our car was created using the vehicleClass/prototype Car// Outputs: falseconsole.log(carinstanceofCar);console.log(car);
The text was updated successfully, but these errors were encountered:
Reading this right here, the Factory Pattern section.
You say that
this.vehicleClass
defaults to Car, but in practice, the first time you do it it default to car but every other time it defaults to whatever class you instantiated last. Try making a truck and then a car:The text was updated successfully, but these errors were encountered: