typescript: Create In reality Non-public Magnificence Fields The use of the #fieldName Syntax

This lesson introduces non-public elegance fields which (in contrast to common elegance fields) can’t be tested or changed outdoor of the category they are outlined in. We are going to distinction non-public elegance fields with TypeScript’s non-public modifier and public elegance fields.

We are additionally going to check out the JavaScript code that the TypeScript compiler emits when downlevel-compiling non-public elegance fields. Notice that this code calls for that the JavaScript runtime put in force the WeakMap information construction (offered as a part of ES2015). After all, we are going to find out how we will be able to use closures to get true privateness promises in older runtime environments that don’t put in force WeakMap.

Further Studying