I have been struggling to understand the reasons why typescript developers choose the way they implemented inheritance.
What I would expect from any language supporting inheritance is these order of work:
- The derived class initialized properties are initialized
- The base class initialized properties are initialized
- The base class constructor runs
- The derived class constructor runs
What apparently happens:
- The base class initialized properties are initialized
- The base class constructor runs
- The derived class initialized properties are initialized
- The derived class constructor runs
I don't yet understand what kinds of benefits come from implementing this kind of inheritance
My question boiling down to this:
What kinds of projects makes this implementation of inheritance perfect for?
EDIT: relevant link to discussion: https://github.com/Microsoft/TypeScript/issues/1617
-
see Why do 'some examples' and 'list of things' questions get closed?gnat– gnat2017年04月19日 12:45:11 +00:00Commented Apr 19, 2017 at 12:45
-
3I don't understand the close vote, it looks both like a legitimate and even interesting question to me. ...*maybe* the reason is related to some JavaScript constraints / compatibility issues.dagnelies– dagnelies2017年04月19日 12:50:25 +00:00Commented Apr 19, 2017 at 12:50
-
1@user108589: your EDIT github link pretty much summarizes the reasoning behind it. There you have your answer.dagnelies– dagnelies2017年04月19日 12:56:51 +00:00Commented Apr 19, 2017 at 12:56
-
3@dagnelies: the question asks for a list of projects (or more precisely, for a list of kinds of projects). List questions are off-topic. The interestingness of the question is irrelevant. There are lots of things that are of interest, but not on-topic.Jörg W Mittag– Jörg W Mittag2017年04月19日 13:02:08 +00:00Commented Apr 19, 2017 at 13:02
-
2It is more than simply following the protocol of another language. The order of initialization ensures that pre-conditions and invariants in the base class are satisfied before the derived class begins execution. This is important for proving correctness.Frank Hileman– Frank Hileman2017年04月25日 16:42:50 +00:00Commented Apr 25, 2017 at 16:42