Private class fields

In many Object-Oriented programming languages that have classes the idea of private and public fields is really important. Now, JavaScript does not have that. Other languages like Java, C# actually have keywords like private that make things private for us they are methods that is only used inside of the the class.

 however an experimental proposal to allow defining private class fields using a hash # prefix is added.

#name = "Mike"

the name is now private data that can be accessed inside of the class.

However, properties and methods can not be private at least for now.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/Private_class_fields

Leave a Reply

Your email address will not be published.

ANOTE.DEV