Destructuring instances with private fields · Issue #4 · tc39/proposal-class-fields (original) (raw)

This repository was archived by the owner on Jan 25, 2022. It is now read-only.

This repository was archived by the owner on Jan 25, 2022. It is now read-only.

@jeffmo

Description

@jeffmo

It just occurred to me that, due to the nature of private-field names, destructuring private fields off an instance into a local binding is not possible with the spec as-is.

I think this could be fixed with a simple tweak to destructuring grammar, though:

const {#pField: pField} = this;

would roughly desguar to

const pField = this.#pField;

Should we include this destructuring grammar in this proposal? Or defer it to a separate proposal?

(I would be in favor of including it if it's as non-controversial as I imagine, defer if it's at all controversial)