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
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.
The text was updated successfully, but these errors were encountered:
There's no special thing called a "fat arrow method declaration". These are just instance members with initializers that happen to be function expressions.
Consider code like this:
classBaseStuff{publicthing=function(){return'hello world';}constructor(){}publicgetHandler(){returnthis.thing;}}classBadStuffextendsBaseStuff{publicsomeOtherThing=this.getHandler();}varx=newBadStuff();// Would fail in proposed initialization orderconsole.log(x.someOtherThing());
Please consider the following code:
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:
It looks logical to put first line of code including call to parent contstuctor AFTER all method declarations in the class.
The text was updated successfully, but these errors were encountered: