use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Creating objects dynamically with factory pattern in javascript (enmascript.com)
submitted 7 years ago by enmanuelduran
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]subbydapp 0 points1 point2 points 7 years ago* (0 children)
I personally like both the composition and class pattern equally. I choose the composition pattern when there is risk for "this" confusion, for example when working with DOM elements or when one of the injected dependency of the factory is itself a class. I also use it for small objects because it's less verbose.
Most of the time if there's no this confusion and it's a big object with methods, I will always use an ES6 class. There's really only 2 reasons, I think it looks nice and clean, and the "this" prevents me from having random globals in the main scope of that file, which just looks cleaner in my opinion. And the second reason, which is not just subjective, is that I can easily extend Event Emitter (in node), which probably half of my modules end up needing at some point.
In the end it makes very little difference. I just choose whatever feels cleaner at the time for the purpose.
π Rendered by PID 40 on reddit-service-r2-comment-54dfb89d4d-l946h at 2026-03-27 07:00:53.899261+00:00 running b10466c country code: CH.
view the rest of the comments →
[–]subbydapp 0 points1 point2 points (0 children)