Contact Emails
Spec
https://github.com/tc39/proposal-class-fields
Summary (taken from our WebFu article)
This private fields proposal provides encapsulation: If you're using an instance of a class, you cannot reference that class's private fields from outside the class body. You can only reference private fields from within the class that defines them.
The new private fields syntax is similar to public fields, except you mark the field as being private by using #. You can think of the # as being part of the field name:
class IncreasingCounter { #count = 0; get value() { console.log('Getting the current value!'); return this.#count; } increment() { this.#count++; } } |
Private fields are not accessible outside of the class body:
const counter = new IncreasingCounter(); counter.#count; // → SyntaxError counter.#count = 42; // → SyntaxError |
This intent to ship includes private static fields as well:
class ClassCounter { static #count = 0; static increment() { this.#count++; } } ClassCounter.#count; // → SyntaxError ClassCounter.increment(); |
Interoperability and compatibility risk
This stage 3 proposal introduces new syntax that was previously a SyntaxError. There’s very low web compat risk.
Firefox: In development
Safari: In development
Edge: No signals
Is this feature fully tested?
Yes, this feature passes V8’s own mjsunit/cctest tests as well as all the Test262 tests.
Tracking bug
Link to entry on the Chrome Platform Status dashboard
https://www.chromestatus.com/feature/6035156464828416
Requesting approval to ship?
Yes. Note that since this is a V8/JS feature, this post is just an FYI to blink-dev — no sign off from Blink API owners is required.
--
--
v8-dev mailing list
v8-...@googlegroups.com
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to v8-dev+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/CADizRgaQiv2%3DmEtPOcprwkGg_KcxCfF7A%3DpPp6q-kCW%3DGN2Mtw%40mail.gmail.com.