About #1, how do you implement "getUser(userData)"?
I'd probably use a switch statement to instantiate the appropriate user type - so something like:
function getUser(userData) { const userType = userData.favorites.food; switch(userType) { case 'pizza': return new PizzaUser(userData); ... } }
You might have included this snippet in the article
Switch statement itself sometime bound you, we can use factory pattern to return the desire class object ;)
Thanks, Abdul. Could you provide an example of what the code might look like? Most factory functions I've seen still involve a switch statement or a series of if/else statements.
This is like the #1 #1 part of the article... You might want to add it.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
About #1, how do you implement "getUser(userData)"?
I'd probably use a switch statement to instantiate the appropriate user type - so something like:
You might have included this snippet in the article
Switch statement itself sometime bound you, we can use factory pattern to return the desire class object ;)
Thanks, Abdul. Could you provide an example of what the code might look like? Most factory functions I've seen still involve a switch statement or a series of if/else statements.
This is like the #1 #1 part of the article... You might want to add it.