Skip to content

Arrow-methods defined after call super() #13834

Closed
hixio-mh/TypeScript
#5
@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().

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

    No branches or pull requests

    Issue actions