Skip to content

Allow this in static initializers #8363

@bterlson

Description

@bterlson

The following is an error:

function factory() {
  return class {
    static x = 1;
    static y = this.x * 2;
  }
}

I can see some potential for confusion here, though I'm not sure what that confusion might be. On the flip side, it seems useful to be able to refer to an anonymous class in a static initializer. It is also easy to teach that "this in instance initializers = the instance, this in static initializers = the class, same as methods vs. static methods."

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureES NextNew featurers for ECMAScript (a.k.a. ESNext)SuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions