What are classes in ES6?
In ES6, Javascript classes are primarily syntactic sugar over JavaScript’s existing prototype-based inheritance. For example, the prototype-based inheritance written in function expression as below,
function Bike(model,color) {
this.model = model;
this.color = color;}
Bike.prototype.getDetails = function() {
return this.model + ' bike has' + this.color + ' color';};
Whereas ES6 classes can be defined as an alternative
class Bike{
constructor(color, model) {
this.color= color;
this.model= model;
}
getDetails() {
return this.model + ' bike has' + this.color + ' color';
}}