Possible inner class scopping

Would it be possible to have a shorthand for defining a inner class scope? Languages like Java and Ruby allow for an inner scope to the class definition.

class Foo {
  class Bar {}

  method() {
    let innerInstance = new Bar(); // OK
  }
}

let outerInstance = new Bar(); // throws ReferenceError

Currently the supported syntax is

class Foo {
  Bar = class Bar {};

  method() {
    let innerInstance = new this.Bar(); // OK
  }
}

// Is not scoped and exposed publicly
let outerInstance = new (new Foo()).Bar();

I felt the former syntax read much better and supported or could encourage others to make more modular OOP designs without exposing implementation details.

You can already basically do this with class private fields (as opposed to the public fields in your second example)

Could you provide an example?

Like this:

class Foo {
  static #Bar = class {}

  method() {
    let innerInstance = new Foo.#Bar(); // OK
  }
}

let outerInstance = new Foo.#Bar(); // Throws SyntaxError
2 Likes