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

    class Monster {
        static allMonsters = [];

        constructor() {
            Monster.allMonsters.push(this);
        }
    }

    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.push(this);
    }
    Monster.allMonsters = [];

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

Peter
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to