📜  JavaScript ES6 类中的私有属性 - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:26.593000             🧑  作者: Mango

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