ES12 Private class

Private Class Methods and Accessors:

The class methods and properties are public by default, but the private methods and properties can be created by using a hash # prefix. The privacy encapsulation has been enforced from the ECMAScript 2021 update. These private methods and properties can only be accessed from inside the class. Refer to the following code snippet to learn how you can use the private methods.

The private accessors are — private Getters and Setters. A Getter allows you to fetch the value of a class property, and a Setter allows you to assign a value to a class property. You can define a private getter by using a hash # prefix.

get #newAccountPassword() {}

Similarly, you can define a private setter by using a hash # prefix.

set #generateAccountPassword(newPassword) {}

Leave a Reply

Your email address will not be published.