class sugar: static inheritance

Peter Michaux petermichaux at
Sun Jun 5 21:35:37 PDT 2011

Are static members inherited? What happens in the last line of the
following code?

    class Monster {
        static allMonsters = [];

        constructor() {

    class Dragon extends Monster {
        constructor() {}

    new Monster();
    Monster.allMonsters.length; // 1
    Dragon.allMonsters.length;  // 0, 1, or error?

Based on my understanding of what the desugared code would be, the
last line above would be an error because Dragon.allMonsters is
undefined. That is, static members are not inherited at all which does
not seem very class-like.

    function Monster() {
    Monster.allMonsters = [];

    function Dragon() {}
    Dragon.prototype = Object.create(Monster.prototype);
    Dragon.prototype.constructor = Dragon;


More information about the es-discuss mailing list