# Possible inner class scopping

**URL:** <https://es.discourse.group/t/possible-inner-class-scopping/954>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [August 29, 2021, 3:38pm UTC](https://es.discourse.group/t/possible-inner-class-scopping/954 "2021-08-29T15:38:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sukima](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/sukima/32/963_2.png) [@Sukima](https://es.discourse.group/u/Sukima)\
**Post date:** [August 29, 2021, 3:38pm UTC](https://es.discourse.group/t/possible-inner-class-scopping/954/1 "2021-08-29T15:38:15Z")

</div>

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.

```javascript
class Foo {
  class Bar {}

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

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

```

Currently the supported syntax is

```javascript
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.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [August 29, 2021, 3:49pm UTC](https://es.discourse.group/t/possible-inner-class-scopping/954/2 "2021-08-29T15:49:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sukima](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/sukima/32/963_2.png) [@Sukima](https://es.discourse.group/u/Sukima)\
**Post date:** [August 29, 2021, 4:04pm UTC](https://es.discourse.group/t/possible-inner-class-scopping/954/3 "2021-08-29T16:04:00Z")

</div>

Could you provide an example?

---

<div class="post-metadata">

**Author:** ![theScottyJam](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/thescottyjam/32/616_2.png) [@theScottyJam](https://es.discourse.group/u/theScottyJam)\
**Post date:** [August 29, 2021, 4:19pm UTC](https://es.discourse.group/t/possible-inner-class-scopping/954/4 "2021-08-29T16:19:30Z")

</div>

Like this:

```javascript
class Foo {
  static #Bar = class {}

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

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

```
