this article was written in 2013
my problem is I can’t understand his point about why we shouldn’t use constructor function. or to be specific I can’t understand what the problem with constructor functions. so If anyone can give me another source explains the problems related to the constructors in js, and what the instanceOf and what the difference between it and prototype; I’ll be so grateful
I searched alot to understand, but my mind is so scattered now.
The ‘problem’ is that some people like to make hyperbolic ‘purist’ statements. Use whatever works for your needs.
It really seemed to me at first that he was talking about his personal opinion. I know that everything has pros and cons, but the title of his article confused me a lot, which made me search a lot if the constructor function is not really used because of security problems or something like that, such as using
eval() for example.
So thank you for pointing out that it is a bit of an exaggeration .
or perhaps it’s an inappropriate article for someone who is still at the beginning of his OOP journey, I think
You really should be using a
class instead, which explicitly requires the
new invocation making the argument a moot point I would think.
I didn’t really read the article but I’m guessing it is pretty outdated. I don’t think using factory functions is considered better (or worse I guess) by most people today.
I understand you, I havn’t learnt Classes yet, but there’s a constructor in it,I think, which makes me comfortable with Classes. constructor seems more organised and clear than factoury function,which he recommended, at least