DEV Community

Discussion on: 7 Exciting New JavaScript Features You Need to Know

Collapse
 
deleteman123 profile image
Fernando Doglio

Nice list! Really looking forward to these. I still think private fields prefixed with "#" is crazy and shouldn't have been accepted, but the rest are cool and I can't wait to use them!
Thanks for sharing!

Collapse
 
mausworks profile image
Rasmus Wennerström

I don't get this one either. Why not conform and use private like in both Java, and TypeScript.

This one is mind boggling.

Collapse
 
kbiedrzycki profile image
Kamil Biedrzycki

Totally agree. Didn't look at specs to be honest, but why it wasn't problem to introduce static keyword and it is a problem indeed with private? 🤔

Collapse
 
emptyother profile image
emptyother

Agreed on the private field prefix. I kinda hope typescript leaves that one out, but they probably have to include it or they would no longer be a superset of js.

Collapse
 
gafi profile image
Mostafa Gaafar • Edited

I had the same feeling at first. Then I read the reasons behind it and it made some sense. Long story short: in a dynamically typed language, giving the engine a hint whether the property you're trying to access is public or private makes it much easier to implement without exposing details of internal private fields. Here's the reasoning behind it github.com/tc39/proposal-private-f...

Another advantage of it is that linters can also understand if you're trying to access a private property outside its class and warn you, which would be impossible without a special identifier