Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Person {
- #age
- constructor(name) {
- this.name = name; // this is public
- this.#age = 20; // this is private
- }
- greet() {
- // here we can access both name and age
- console.log(`name: ${this.name}, age: ${this.#age}`);
- }
- }
- let joe = new Person('Joe');
- joe.greet();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement