You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem is that in the init of ChildClass, "onClick" is still undefined because in the compiled JS it is only defined after the super call. This comes up generally when I call functions in the super class that are likely to be overridden in child classes and the child implementations use arrow functions defined in the child class.
I was wondering what was the reason behind this order and wouldn't it be possible to reverse it (ie. define arrow functions first, call super afterwards).
I think it's related to this error message which pops up if you try to call init manually before super():
"A 'super' call must be the first statement in the constructor when a class contains initialized properties or has parameter properties"
My view of this is that the only reason I'm using arrow functions generally is to make sure the scope (this) is correct, so ideally it would be good to be able to work with them just like if they were "non-arrow", normal prototypical functions.
The text was updated successfully, but these errors were encountered:
There isn't any sensible way to redefine the order of initialization of a TypeScript class. See #1617 for an extended explanation of how class emit and other constraints prevent any other initialization order than the one you see today.
More generally, the principle of "don't call virtual methods from constructors" remains good OOP advice.
I have a problem I've encountered a few times:
The problem is that in the init of ChildClass, "onClick" is still undefined because in the compiled JS it is only defined after the super call. This comes up generally when I call functions in the super class that are likely to be overridden in child classes and the child implementations use arrow functions defined in the child class.
I was wondering what was the reason behind this order and wouldn't it be possible to reverse it (ie. define arrow functions first, call super afterwards).
I think it's related to this error message which pops up if you try to call init manually before super():
Related issues are:
https://typescript.codeplex.com/discussions/444975
http://typescript.codeplex.com/workitem/91
My view of this is that the only reason I'm using arrow functions generally is to make sure the scope (this) is correct, so ideally it would be good to be able to work with them just like if they were "non-arrow", normal prototypical functions.
The text was updated successfully, but these errors were encountered: