Say I have a class Animal that I want to define in JavaScript. What are the advantages and disadvantages to declaring it as...
class Animal {
constructor(type, noise) {
this.type = type;
this.noise = noise;
}
makeNoise() {
console.log(this.noise);
}
}
versus declaring it as...
function Animal(type, noise) {
this.type = type;
this.noise = noise;
this.makeNoise = function () {
console.log(this.noise);
}
}
The only thing that I notice is different is that the latter example can actually have private members (declared using var, let, or const declarations), but that was all I could really see.