# How is it possible to have a \_subset\_ of the private fields of a class?

**URL:** <https://es.discourse.group/t/how-is-it-possible-to-have-a-subset-of-the-private-fields-of-a-class/1217>\
**Category:** Spec Reading\
**Created:** [February 20, 2022, 11:01am UTC](https://es.discourse.group/t/how-is-it-possible-to-have-a-subset-of-the-private-fields-of-a-class/1217 "2022-02-20T11:01:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dop251](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/dop251/32/1251_2.png) [@dop251](https://es.discourse.group/u/dop251)\
**Post date:** [February 20, 2022, 11:01am UTC](https://es.discourse.group/t/how-is-it-possible-to-have-a-subset-of-the-private-fields-of-a-class/1217/1 "2022-02-20T11:01:07Z")

</div>

Hi.

The current specification says ([ECMAScript® 2024 Language&nbsp;Specification](https://tc39.es/ecma262/#sec-runtime-semantics-classdefinitionevaluation)):

> because field initializers can throw during class instantiation, an individual object may have some proper subset of the private fields of a given class

I'm wondering if that's correct. My understanding is if a field initializer throws, the instantiation fails and so the instance never becomes available. Am I missing something?

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [February 20, 2022, 12:25pm UTC](https://es.discourse.group/t/how-is-it-possible-to-have-a-subset-of-the-private-fields-of-a-class/1217/2 "2022-02-20T12:25:19Z")

</div>

A reference to the instance is accessible in the field initialisers that have run before the construction fails.

```javascript
function error() { throw new Error() }

new class {
  #a;
  #b = console.log(#a in this, #b in this);
  #c = error();
}
// logs: true, false

```

---

<div class="post-metadata">

**Author:** ![dop251](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/dop251/32/1251_2.png) [@dop251](https://es.discourse.group/u/dop251)\
**Post date:** [February 20, 2022, 12:42pm UTC](https://es.discourse.group/t/how-is-it-possible-to-have-a-subset-of-the-private-fields-of-a-class/1217/3 "2022-02-20T12:42:09Z")

</div>

Got it, thanks!
