In this post we’ll shed light on ECMAScript private fields and see how they compare to the TypeScript private modifier.

JavaScript private class fields and the need for privacy

closure is the only JavaScript native mechanism for protecting variables from access.

Closures are the foundation for a lot of private-like patterns, like the popular module pattern. But after ECMAScript 2015 classes took over in recent years, developers felt the need for more control over classes member privacy.

The class field proposal (at the time of writing in stage 3) tries to solve the problem with the introduction of private class fields.

Let’s see how they look like.

#typescript #javascript

JavaScript Private Class Fields and The TypeScript Private Modifier
1.10 GEEK