With ES5 there is performances optimum way to create Objects and their members like this.
var Car = function () {
this.milage = 0;
}
Car.prototype.run = function () {
this.milage++;
}
But with ES6 we use class
syntax to create classes.
class Car {
constructor(){
this.milage = 0;
}
}
when we use this ES6 approach, I had a question of what is the most efficient way of creating class members?
is it like creating class member within the class
class Car {
constructor(){
this.milage = 0;
}
run() {
this.milage++;
}
}
or, using the prototype approach.
Car.prototype.run = function () {
this.milage++;
}