Simply put, the reason to use this is ease of understanding the code. Without class field declarations, you'd do something like
class Person {
constructor() {
this.firstName = "Mike";
this.lastName = "Patel";
this.getName = () => {
return this.firstName + " " + this.lastName;
};
}
}
var p = new Person();
console.log(p.firstName); // Mike
console.log(p.lastName); // Patel
console.log(p.getName); // () => { return this.firstName + " " + this.lastName; }
console.log(typeof p.getName); // function
console.log(p.getName()); // Mike Patel
This works but now you have both the method declaration and the instance properties all collected in the constructor. You could have even more methods, however, which means that your class definition would look rather meaningless overall:
class MyClass() {
constructor(someArg) {
this.prop1 = 1;
this.prop2 = 2;
this.prop3 = 3;
this.prop4 = someArg;
this.method1 = () => {}
this.method2 = () => {}
this.method3 = () => {}
this.method4 = () => {}
}
}
and so on. Again, everything is in the constructor. If you have a lot of code, it becomes harder to read what is what. And if the constructor takes any arguments, then you have the extra overhead of keeping track of those. Simply put, it's hard to read, hard to maintain for no real benefit. You are stuffing everything in the same place.
With class field declarations, you separate them and you get
class MyClass() {
/* properties - don't depend on the constructor*/
prop1 = 1;
prop2 = 2;
prop3 = 3;
prop4; /* this is a property that this class will have -
I don't need to look at the constructor to know about it */
/* easy to see what the constructor does that is only about *constructing* the object */
constructor(someArg) {
this.prop4 = someArg;
}
/* methods are separated from the rest of the properties and construction logic */
method1 = () => {}
method2 = () => {}
method3 = () => {}
method4 = () => {}
}
So, all in all, it's not revolutionary but it is slightly nicer syntax that makes it easier to express what a class has.