Prefer ES6 classes over ES5 functions

Prefer ES6 classes over ES5 functions

Tags
Clean Code
Javascript
Software Development
Published
Published August 15, 2022
Author
Due Date
☑️ Topic: Classes
 
☑️ Idea: ES6 is better than ES5 for readable class inheritance, construction and methods.
 
☑️ Benefits: Readability, Maintainability.
 
☑️ Guideline: Use small functions when you need something simple and use ES6 classes when you need larger and more complex objects.
 
// BAD const Animal = function(age) { if (!(this instanceof Animal)) { throw new Error("Instantiate Animal with `new`"); } this.age = age; }; Animal.prototype.move = function move() {}; // GOOD class Animal { constructor(age) { this.age = age; } move() {/* ... */} }