Skip to content

Factory pattern code example bug removal - #227

Open
omamazainab wants to merge 1 commit into
addyosmani:masterfrom
omamazainab:master
Open

omamazainab wants to merge 1 commit into
addyosmani:masterfrom
omamazainab:master

Conversation

@omamazainab

Copy link
Copy Markdown

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,

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.

Correction

we set the default value of options to an empty object. It will then allow assigning all of the default values

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants