← Back to release summary

Private methods and accessors

Category
JavaScript
Type
New or changed feature
Status
Enabled by default (Chrome 84)
Intent stage
Prepare to ship

Summary

Keeping state and behavior private to a class lets library authors present a clear, stable interface, while changing their code over time behind the scenes. The class fields proposal provides private fields for classes and instances, and this proposal builds on that by adding private methods and accessors (getter/setters) to JavaScript. With this proposal, any class element can be private.

Motivation

https://v8.dev/features/class-fields https://github.com/tc39/proposal-private-methods/blob/master/README.md

Standards & signals

Docs: https://docs.google.com/document/d/1T-Ql6HOIH2U_8YjWkwK2rTfywwb7b3Qe8d3jkz72KwA/edit

Explainers: https://v8.dev/features/class-fields https://github.com/tc39/proposal-private-methods/blob/master/README.md

View on chromestatus.com