All:
I am pretty new to ES6 and typescript and currently study both side by side.
When I come to Class definition part, there is one question:
Is there a major syntax between them in class declaration:
What I find out is:
In ES6, there is only method can be declared but no member :
class Greeter {
constructor(message) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
While in TypeScript, it allows to declare the member variable as well:
class Greeter {
// although it declare a variable "greeting" here, but I am not sure if it allows assignment initialization
greeting: string;
constructor(message: string) {
this.greeting = message;
}
greet() {
return "Hello, " + this.greeting;
}
}
I am not sure if this is the major syntax diff(plus access modifier, there is one related question about modifier: I read that ES6 class can not define static member, then what is the point to allow define static method?) between them?
If more than this, what else need to pay attention?
Thanks