专用字段(和方法)正在ECMA标准中实现。您可以立即从[babel 7和Stage3预设开始使用它们。
class Something { #property; constructor(){ this.#property = "test"; } #privateMethod() { return 'hello world'; } getPrivateMessage() { return this.#privateMethod(); }}const instance = new Something();console.log(instance.property); //=> undefinedconsole.log(instance.privateMethod); //=> undefinedconsole.log(instance.getPrivateMessage()); //=> hello world


