Skip to content
This repository has been archived by the owner on Apr 9, 2020. It is now read-only.

static properties are undefined #98

Closed
tobiasmuecksch opened this issue Jun 8, 2016 · 4 comments
Closed

static properties are undefined #98

tobiasmuecksch opened this issue Jun 8, 2016 · 4 comments

Comments

@tobiasmuecksch
Copy link

tobiasmuecksch commented Jun 8, 2016

Hey there,

I tried the following snippet:

class Car {
  startEngine() {
    console.log("Engine started!");
  }
}

class Ferraro extends Car {
  static myStaticProp = 21;

  logStatic() {
    console.log(this.myStaticProp);
  }
}



var car1 = new Ferraro();
car1.logStatic();

I compiled it via babel with es2015 and stage-0. When I run the resulting code, the last line echoes undefined.

@dozoisch
Copy link

dozoisch commented Jun 8, 2016

What happens if you do Ferraro.myStaticProp instead. I don't think static are accessible from the instance directly.

@tobiasmuecksch
Copy link
Author

tobiasmuecksch commented Jun 13, 2016

@dozoisch Well, that is contradictory to the static properties one might be used to in other languages like Java.

I can't think of any case this bug/feature might be useful.

@Marsup
Copy link

Marsup commented Jun 13, 2016

This is exactly like that in C# and C++, maybe Java is the exception and not the norm.

@tobiasmuecksch
Copy link
Author

tobiasmuecksch commented Jun 13, 2016

@Marsup Thank you for the clarification. Sometimes one is tempted to believe Java is the overall standard 😐

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants