0

In ES5, we can declare static properties and methods for constructors:

function Person(name){
    this.name = name;
}

Person.staticProperty = 123;
Person.staticMethod = function(){};

Some built-in objects also provide static properties and methods:

Math.PI;    // 3.141592653589793
Math.floor(33.7);   // 33

However, ES6 classes allow only static methods:

class Foo {
    static staticMethod(){};
    static staticProperty: 123;    // Error
}

What is the reasoning behind not allowing static properties?

NL500
  • 1,165
  • 2
  • 9
  • 13
  • 2
    The ECMAScript specification is not carved into stone tablets by the finger of the Almighty. Adding class fields is at stage 3 of the TC39 proposal process. https://github.com/tc39/proposal-class-fields – Jared Smith Oct 05 '17 at 17:49
  • @Jared Smith I don't think this is a duplicate question. The answers in the link simply give workarounds, but I'm asking about the reason the ECMAScript committee did not implement class fields in the first place. It would be a lot simpler than doing one of those workarounds. – NL500 Oct 05 '17 at 18:06
  • 2
    in that case, I would still vote to close as off-topic since this isn't a programming question and therefor does not belong on stack overflow. I am not sufficiently curious to dig through the old ES Discuss thread and TC39 meeting notes to find out, but would guess that they didn't implement it (yet) because someone said "what about the impact on performance/feature X/future extensibility?" and someone(s) said "huh, we'd better table that for next time and just get the basic class proposal implemented" and because it was trivial for developers to roll their own in the mean time. – Jared Smith Oct 05 '17 at 18:15
  • In any case, I was one vote of 4 and Barmar has the golden hammer, so persuading me of your case doesn't really help you much. – Jared Smith Oct 05 '17 at 18:17
  • @Jared Smith OK, I understand :) – NL500 Oct 05 '17 at 18:56
  • 3
    Stack Overflow is not a good place to ask about design decisions about a particular committee. You would probably get faster or at least more accurate answers if you directly reach to them, either on the mailing list or e.g. on Twitter. – Felix Kling Oct 05 '17 at 20:03

0 Answers0