When I say ES6 Classes, you might go YAY 🎊 JavaScript finally introduced a new object-oriented inheritance model. Well, not exactly. It’s still using the existing prototype-based inheritance (labelled as “Old way” in the photo). But now it just look more like Object Oriented Programming (OOP). Yay, I think this syntactical sugar is GREAT!
// Old way
var Meal = function(food) {
this.food = food;
};
Meal.prototype.eat = function() {
return '😋';
};
// Classes in ES6
class Meal {
constructor(food) {
this.food = food;
}
eat() {
return '😋';
}
}
#javascript #es6 #web-development