Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inheritance and property default value #3280

Closed
obarannikov opened this issue May 27, 2015 · 1 comment
Closed

Inheritance and property default value #3280

obarannikov opened this issue May 27, 2015 · 1 comment
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Duplicate An existing issue was already created

Comments

@obarannikov
Copy link

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

@danquirk
Copy link
Member

See #1617 (comment)

@danquirk danquirk added By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Duplicate An existing issue was already created labels May 27, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
By Design Deprecated - use "Working as Intended" or "Design Limitation" instead Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants