Not forcing super in derived class's constructor?

Claude Pache claude.pache at gmail.com
Tue May 12 19:15:19 UTC 2015


> Le 12 mai 2015 à 04:51, Glen Huang <curvedmark at gmail.com> a écrit :
> 
> However, forcing super has one major drawback: it becomes cumbersome when you don't want to call superclass's constructor(), that you want to define a new constructor() to override it.
> 
> When that happens, you have two choices:
> 
> 1. don't use "this", create a new object and return it.
> 2. use the old way to create "class"

To be short, for me, there are two more choices:

3. maybe subclassing that particular class is not the correct abstraction here;
4. correct the design of the super-constructor, so that it is able to just do the minimum required stuff.

Also, as an alternative to your choice #2, there is the following possibility that I don't propose very seriously, although I wonder if it might be more semantically correct than subclassing in your use case. Instead of `class B extends A { }`, write:

```
class B { }
Object.setPrototypeOf(B, A)
Object.setPrototypeOf(B.prototype, A.prototype)
```

—Claude


More information about the es-discuss mailing list