0

Is there late static binding in es6 classes.(without hacks)

For example:

class Base {
    static make() {
        return new  ....
    }
}

class Implementation1 extends Base {}

class Implementation2 extends Base{}

Basically I want to set base static methods in the base class and do this:

Implementation1::make(); Implementation2::make();

Without copying the method in each class.

The alternative in PHP is:

return new static();
  • They already are. I copy-pasted your code, replaced `return new ....` by `return new String("foobar")`, and then ran `Implementation1.make()`, and it returned `String {"foobar"}`. Works like a charm. – Seblor Jun 25 '19 at 08:38
  • I meant when I call Implementation1::make() to return new instance of Implementation1 class and the same for Implementation2 class - to be dynamic. –  Jun 25 '19 at 08:41
  • 1
    Late binding uses the `this` keyword in JavaScript methods - in static ones as well. – Bergi Jun 25 '19 at 08:58

0 Answers0