Hacker News new | ask | show | jobs
by kremlin 4051 days ago
This is just in time. I just read a chapter in a JavaScript book about OO programming in JS and finished the chapter very confused. It demonstrated about 12 different patterns people have used for creating 'classes' and 'subclassing' them, each with a list of advantages and disadvantages.

Eg there's the 'parasitic instantiation' and then there's the 'Constructor pattern' and then there's the 'Parasitic Constructor', and there's like 3 other patterns that have their own permutations. Coming from Python and then Java, where classes just work...it's kind of annoying.

[edit] I was being a bit hyperbolic, the book discussed 6 ways of inheritance in JS, those being (1) Prototype Chaining (2) Constructor Stealing (3) Combination Inheritance <- most popular one according to the book (4) Prototypal Inheritance (5) Parasitic Inheritance (6) Parasitic Combination Inheritance <- pattern that is generally the best according to the book

1 comments

Inheritance is rarely necessary