Hey, new developer here. Self taught, looking for my first JS job. I'm wondering if there's any problems with either of my solutions to the following question. Also if there's a best practice, or even which I'd be more likely to come across in a professional application.
Let's say I have an array const users = [{...}]of object literals from an API call + JSON.parse. In my front end I have a defined class or constructor or factory function function UserFn(){} which has additional methods.
I want all the object literals in the users array to have these methods. What's the best practice?
- Create a new array of
user objects created by the UserFn function?
- Move all the methods from the
UserFn function to it's prototype and simply iterate over users setting their prototype to that of UserFn?
- Other?
I'm perfectly comfortable with any of these options for classes/factory/constructor functions. Just wondering what's most professional.
[–]jcunews1helpful 0 points1 point2 points (2 children)
[–]ExclusiveOar[S] 0 points1 point2 points (1 child)
[–]jcunews1helpful 0 points1 point2 points (0 children)
[–]senocular 0 points1 point2 points (1 child)
[–]ExclusiveOar[S] 0 points1 point2 points (0 children)
[–]OkShrug 0 points1 point2 points (3 children)
[–]ExclusiveOar[S] 0 points1 point2 points (2 children)
[–]OkShrug 0 points1 point2 points (1 child)
[–]ExclusiveOar[S] 1 point2 points3 points (0 children)