O'Reilly logo
  • Karl Giesing thinks this is interesting:

With class constructors, you are forced (not really, but it is strongly suggested) to do both construction and initialization in the same step.


Cover of You Don't Know JS: this & Object Prototypes


I've never seen this "forcing" anywhere in a classical OOP language, and in fact there are thousands that have separate constructors and "init" methods.

What this guy doesn't realize is that he is using a "constructor" when he calls Object.create(). That is literally all constructors are supposed to do in classical OOP languages.

He is probably conflating "initialization" where variable values are set when the object is created in memory, and "initialization" where values are set with "default values that make sense for the implementation." JavaScript doesn't even support the first, that initialization is done by the engine, and that is the only &quo...