Skip to content

Inheritance and property default value #3280

Closed
@obarannikov

Description

@obarannikov

Please see following:

class A {
    name: String = 'test A';
    constructor() {
        console.log(this.name);
    } 
}

class B extends A {
    name: String = 'test B'
}

new B(); // 'test A'

It will return 'test A', but 'test B' is more obvious output for this code. And also it is very handy to have an ability to override property default value in subclasses.

It cam be easily achieved, if implicit super() call on B will be made after property assignment, just compile to this:

...
    function B() {
        this.name = 'test B';
        _super.apply(this, arguments);
    }
...

instead of this:

...
    function B() {
        _super.apply(this, arguments);
        this.name = 'test B';
    }
...

You can see example here: http://bit.ly/1cjaMeJ

Metadata

Metadata

Assignees

No one assigned

    Labels

    By DesignDeprecated - use "Working as Intended" or "Design Limitation" insteadDuplicateAn 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