Grouped Accessors and Auto-Accessors S1
- Stage: Stage 1
- Status: Active
- ECMAScript edition: —
- Synchronized: Aug 28, 2026
- 中文译文 · Source repository
This proposal introduces syntax for grouped accessors in classes and object literals, and auto-accessors in classes. Grouped accessors allow defining get and set methods together, while auto-accessors provide a simplified form with implicit private backing fields. It aims to improve readability, editor experience, and decorator capabilities.
The README below comes from the upstream repository and may contain outdated stage or status metadata. Use the proposal details above as the current source of truth.
Grouped Accessors and Auto-Accessors for ECMAScript
This introduces an investigation into new syntax for grouped accessors to classes and object literals and auto-accessors to classes.
A grouped accessor is a single declaration that contains either or both both of the get and set methods for an accessor.
An auto-accessor is a simplified variant of a grouped accessor that elides the bodies of the get and set methods and
introduces a private backing field used by both the getter and setter.
Under Consideration: We may consider expanding auto-accessors to work on object literals in the future, however the necessary private name semantics are currently not defined for object literals.
Status
Stage: 1
Champion: Ron Buckton (@rbuckton)
For detailed status of this proposal see TODO, below.
Authors
- Ron Buckton (@rbuckton)
Grouped Accessors
A grouped accessor is essentially a way to define either one or both of the get and set methods of an accessor in a
single logical group. This provides the following benefits:
- The
getandsetdeclarations are logically grouped together, which improves readability.- This can also result in an improved editor experience in editors with support for folding (i.e.,
▶ accessor x { ... })
- This can also result in an improved editor experience in editors with support for folding (i.e.,
- A grouped
getandsetaccessor pair with a ComputedPropertyName only needs to have its name evaluated once. - In a
class, the setter for a public property can be marked as private using#set, this introduces both a public binding for the identifer, and a private binding for the identifier (but prefixed with#). For example:Introduces aygetter on the prototype and a#ysetter on the instance. - A decorator applied to the group could observe both the
getandsetmethods simultaneously for entangled operations. For example:- This allows you to reuse a decorator designed for an
accessorfield with a pairedgetandsetdeclaration. - This also provides a capability that was present in the Stage 1 Decorators proposal that is currently missing in the Stage 3 Decorators proposal.
- This allows you to reuse a decorator designed for an
Auto-Accessors
An auto-accessor is a simplified version of a grouped accessor that allows you to elide the body of the get
and set methods, and optionally provide an initializer. An auto-accessor introduces a unique unnamed private field on
the class which is wrapped by a generated getter and an optional generated setter. Using #set instead of set indicates that a
private setter of the same name as the public member (but prefixed with #) exists on the object and provides privileged access to set the
underlying value.
This provides the following benefits:
- Introduces accessors that can be overridden in subclasses without excess boilerplate.
- Provides a replacement for fields that allows you to observe reading and writing the value of the field with decorators.
- Allows you to perform initialization inline with the declaration, similar to fields.
- Allows you to decorate the individual
getorsetmethod stubs independently of the entire accessor. For example:- This allows you to reuse a decorator designed only for a
getor asetmethod in the context of anaccessorfield definition.
- This allows you to reuse a decorator designed only for a
Proposed Syntax
Please see the specification for the proposed syntax.
Proposed Semantics
Please see the specification for the full proposed semantics. The following represents some approximate semantics for this proposal. The gist of which is the following:
- Only
accessorproperties with IdentifierName names can have a#setstub or#setmethod: - You cannot have both a
setand a#setin the same group: - You cannot combine
get,set, or#setstub definitions withget,set, or#setmethods: - You cannot combine
get,set, or#setmethods with an initializer: - You cannot have an
accessorproperty that has a#setstub or method that collides with another private name on the class: - Object literals cannot have auto-accessors:
Interaction with Decorators
This proposal is intended to dovetail with the Decorators proposal and shares syntax with auto-accessors in that proposal. This proposal expands upon the Decorators proposal in the following ways:
- By adding an AccessorGroup to an auto-accessor, you are able to decorate both the entire
accessordeclaration as well as the individualgetandsetmethod stubs: - A decorator on a grouped accessor is able to access both the
getandsetdeclarations, similar to early decorator implementations in TypeScript and Babel: - Similar to auto-accessors, grouped accessors can be decorated both at the
accessordeclaration level and at the individual getter and setter declarations:
In addition, some aspects of auto-accessors that may at first seem like edge cases become powerful capabilities with decorators:
This proposal also helps to provide consistency between decoration forms, which aids in reusability of decorators:
Prior Art
Examples
Grouped Accessors
Auto-Accessors
TODO
The following is a high-level list of tasks to progress through each stage of the TC39 proposal process:
Stage 1 Entrance Criteria
- Identified a "champion" who will advance the addition.
- Prose outlining the problem or need and the general shape of a solution.
- Illustrative examples of usage.
-
High-level API.
Stage 2 Entrance Criteria
- Initial specification text.
- Transpiler support (Optional).
Stage 3 Entrance Criteria
- Complete specification text.
- Designated reviewers have signed off on the current spec text.
- The ECMAScript editor has signed off on the current spec text.
Stage 4 Entrance Criteria
- Test262 acceptance tests have been written for mainline usage scenarios and merged.
- Two compatible implementations which pass the acceptance tests: [1], [2].
- A pull request has been sent to tc39/ecma262 with the integrated spec text.
- The ECMAScript editor has signed off on the pull request.