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

Architectural error #9344

Closed
uMaxmaxmaximus opened this issue Jun 24, 2016 · 1 comment
Closed

Architectural error #9344

uMaxmaxmaximus opened this issue Jun 24, 2016 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@uMaxmaxmaximus
Copy link

uMaxmaxmaximus commented Jun 24, 2016

Cant call static owerriden methods, if i write Animal.run() this is code not use Cat.run owerriden method. i need write this.constructor.run() but it get compilation error.

class Animal {

    static run (){
        alert('Animal run')
    }

    run(){
        this.constructor.run() // compile error
        // if i write Animal.run() this code not use Cat.run owerriden method
    }

}


class Cat extends Animal {

    static run (){
        super.run()
        alert('Cat jump')
    }

}

let cat = new Cat()
cat.run()

solution

add keyword static for access to current static props, static will be alias for this.constructor in self methods, and alias for this in static methods

and code will be:

class Animal {

    static run (){
        alert('Animal run')
    }

    run(){
        static.run() // compile to this.constructor.run()
    }

}


class Cat extends Animal {

    static run (){
        super.run()
        alert('Cat jump')
    }

}

let cat = new Cat()
cat.run() // alert('Animal run') alert('Cat jump')

dangers

Static keyword to be used in the following standards and ES have different semantics

@mhegazy
Copy link
Contributor

mhegazy commented Jun 24, 2016

Duplicate of #3841

@mhegazy mhegazy added the Duplicate An existing issue was already created label Jun 24, 2016
@mhegazy mhegazy closed this as completed Jun 24, 2016
@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
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

2 participants