Answers for "private methods in classesjs"

5

private methods in classesjs

class Something {
  #property;

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

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

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

const instance = new Something();
console.log(instance.property); //=> undefined
console.log(instance.privateMethod); //=> undefined
console.log(instance.getPrivateMessage()); //=> hello worl
Posted by: Guest on March-03-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language