📜  js es6 类私有方法 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:50.357000             🧑  作者: Mango

代码示例2
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