Skip to content

Arrow-methods defined after call super() #13834

@vasa-c

Description

@vasa-c

TypeScript Version: 2.1.5

Code

abstract class Base {

    public constructor(protected el: Element) {
        el.addEventListener("click", this.onClick);
    }

    protected onClick = (): void => {
        console.log("Base click");
    }
}

class Child extends Base {

    protected onClick = (): void => {
        console.log("Child click");
    }
}

const widget = new Child(document.getElementById("el"));

Expected behavior:

Child click in console after a click

Actual behavior:

Base click

Why

Compiled JS:

var Child = (function (_super) {
    __extends(Child, _super);
    function Child() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.onClick = function () {
            console.log("Child click");
        };
        return _this;
    }
    return Child;
}(Base));

Method onClick of Child defined after _super.apply().

Activity

RyanCavanaugh

RyanCavanaugh commented on Feb 2, 2017

@RyanCavanaugh
Member

See #1617

locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @vasa-c@RyanCavanaugh

      Issue actions

        Arrow-methods defined after call super() · Issue #13834 · microsoft/TypeScript