Skip to content

Instantly share code, notes, and snippets.

@joliss
Created October 20, 2015 15:06
Show Gist options
  • Select an option

  • Save joliss/9b3d3e5167e644e49b16 to your computer and use it in GitHub Desktop.

Select an option

Save joliss/9b3d3e5167e644e49b16 to your computer and use it in GitHub Desktop.

If we make call constructors static and inherited, then maybe the name call constructor becomes a bit odd.

  1. The best alternative I could come up with is static constructor:

    class Base {
      static constructor() { return new this(); }
    }

    I like it because it fits nicely with the existing syntax; and it communicates clearly that this is the class thanks to the static keyword.

  2. If we're completely honest, a "constructor" is something that initializes a newly-created instance (this), but our "static constructor" doesn't actually do that. So perhaps "constructor" is a mis-nomer. I'm looking for something along the lines of static [[Call]]():

    // Not actually viable syntax, of course
    class Base {
      static [[Call]]() { return new this(); }
    }

    I'm not actually suggesting this syntax. The terminology is better, but I can't come up with something that's syntatically acceptable. Maybe someone else has an idea?

    But if not, I'm thinking static constructor would be pretty good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment