I was looking into ES6, because it appears to be promoted when writing reactJS apps. I was a bit surprised about the way constructors work:
class Human{
constructor(name){
this.name = name;
}
toString(){
return "Name = " + this.name;
}
}
class Person extends Human{}
var person = new Person("kim");
How likely is it that one of the following might make my app brittle when writing a front end app in JS using class based system:
Optional question:
The secondary question I have is on how smart of a decision it would be to use ES6 for large production apps today and if it's useful to just use ES6 for experimenting for now. I'm not sure whether it's misplaced to think that JS is tending towards a full fledged class based system like Java, and that things might change (evolute) faster than my code base will be able to digest.
Parametered constructors are implicitly inherited - is this a good idea overall and what is the chance that it will stay like that?
Yes, it will stay like that. If you are not providing a constructor, the default is to call the parent constructor with all the parameters.
This is a good idea, as class
does oblige you to call super()
within the constructor (which is necessary at least for inheriting builins, and a good practise anyway). If there was no default constructor, you'd have to explicitly provide it yourself, which would have led to an increase in boilerplate code (and the goal of the class
keyword was to avoid that).
Disability to overload constructors within the same class; Disability to overload based on parameter types
No. Of course, in JS you cannot have multiple constructors for a class, but you can still overload it, both on the number of passed arguments and their types.
Is ES6 production-ready?
Yes. The standard is adopted, there is no more experimentation with it. Transpilers do support all of the main useful syntax features.
I'm not sure whether it's misplaced to think that JS is tending towards a full fledged class based system like Java
Yes, that's misplaced. JS does not have a Java-like class system and will hardly ever get one. See also Will JavaScript ever become a 'proper' class based language?.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With