Skip to content

Class inheritence: put call to parent constructor after "fat arrow" method declarations. #2488

Closed
@sqlly

Description

@sqlly

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" instead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions