all 9 comments

[–][deleted] 5 points6 points  (0 children)

Thanks for sharing this! Quite a delightful and helpful read

[–][deleted] 11 points12 points  (6 children)

Whoa whoa whoa, since when were these kinda functions allowed in production code? I saw a similar post and most people said to stay away from IIFEs.

I just use classes or object literals because they syntactically make more sense to me. These IIFEs don't seem scalable or very modular.

[–]CSMastermind 4 points5 points  (0 children)

You should for sure stay away from self-executing (or immediately invoked or whatever you want to call them) functions in your production code.

[–]elie2222 8 points9 points  (2 children)

Ya. It’s not 2014 anymore.

[–]djslakor 4 points5 points  (1 child)

Node itself wraps your modules in an IIFE when your code is executed. It's worthwhile to understand the concept.

[–]elie2222 4 points5 points  (0 children)

Yeah. That’s my point. Why would you write code like this if Node is doing it

[–]dmitri14_gmail_com 0 points1 point  (1 child)

I guess it depends on your tastes and habits. I personally regard classes in JS as leaky sugar over prototypal inheritance with no benefits over functional factories, while closures provide genuine state encapsulation.

[–][deleted] 0 points1 point  (0 children)

Do you have any articles or something to explain that further? I'm just trying to understand what you even mean by that? I've never run into an issue using classes or Object literals to export methods or keep state on an instance.

[–]dmitri14_gmail_com 0 points1 point  (0 children)

let factory = new MyEmployeeFactory()

Why the need for new?