Closed
Description
Please consider the following code:
interface MenuItem{
caption:string;
handler: string;
handlerFunction?: Function;
}
class BaseStuff{
public menu:Array<MenuItem>=[];
constructor (menu:Array<MenuItem>){
this.menu=menu;
this.prepareMenu(menu);
}
public prepareMenu(menu:Array<MenuItem>){
for (var item in menu){
item.handlerFunction=this[item.handler];
}
}
}
class BadStuff extends BaseStuff{
public someAction=()=>{
alert("SomeAction from BadStuff called");
}
}
var bad=new BadStuff([{caption: "test", handler: "someAction"}]);
I need a class, that will send, say, menu structure to the parent where actual handler function will be found. The problem is that when methods is declared via fat arrow, the call to parent constructor goes before the actual method will be defined:
_super.apply(this, arguments);
this.someAction = function () {
alert("SomeAction from BadStuff called");
};
It looks logical to put first line of code including call to parent contstuctor AFTER all method declarations in the class.