2 ms·
Classes enforce a strict hierarchical relationship which is rarely how the real world works. And you also inherit everything from a parent class whether you nee
by tchaffee 10y ago
Classes enforce a strict hierarchical relationship which is rarely how the real world works. And you also inherit everything from a parent class whether you need it or not. One alternative to class inheritance possible with javascript is object composition (usually Object.assign()) which does not enforce a hierarchical relationship and you can use only what you want from other objects. More flexible, less brittle. Eric Elliot goes into details with concrete examples in this article. https://medium.com/javascript-scene/master-the-javascript-interview-what-s-the-difference-between-class-prototypal-inheritance-e4cd0a7562e9 https://medium.com/javascript-scene/master-the-javascript-in...