I'm having trouble finding information about the difference between these two ways of writing classes. Do they behave differently? why might you use one over the other ?
var Greeter = function(greeting) {
this.greeting = greeting;
};
Greeter.prototype.greet = function() {
console.log(this.greeting);
}
var hello = new Greeter("hello");
hello.greet();
versus:
class Greeter {
greeting;
constructor(greeting) {
this.greeting = greeting;
}
};
Greeter.prototype.greet = function() {
console.log(this.greeting);
}
var hello = new Greeter("hello");
hello.greet();