Tuesday, 27 April, 2021 UTC


This lesson introduces private class fields which (unlike regular class fields) cannot be examined or modified outside of the class they're defined in. We're going to contrast private class fields with TypeScript's `private` modifier and public class fields. We're also going to take a look at the JavaScript code that the TypeScript compiler emits when downlevel-compiling private class fields. Note that this code requires that the JavaScript runtime implement the `WeakMap` data structure (introduced as part of ES2015). Finally, we're going to learn how we can use closures to get true privacy guarantees in older runtime environments that do not implement `WeakMap`. ## Additional Reading - [Private class fields](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields) - [Class field declarations for JavaScript](https://github.com/tc39/proposal-class-fields) - [Private methods and getter/setters for JavaScript classes](https://github.com/tc39/proposal-private-methods)