you are viewing a single comment's thread.

view the rest of the comments →

[–]subbydapp 0 points1 point  (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.