Answers for "Private properties in JavaScript ES6 classes"

0

Private properties in JavaScript ES6 classes

class Something {
  #property;

  constructor(){
    this.#property = "test";
  }

  #privateMethod() {
    return 'hello world';
  }

  getPrivateMessage() {
      return this.#property;
  }
}

const instance = new Something();
console.log(instance.property); //=> undefined
console.log(instance.privateMethod); //=> undefined
console.log(instance.getPrivateMessage()); //=> test
Posted by: Guest on September-08-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language