版本:
node -v
v12.11.0
测试
'use strict'
class a1 {
//私有属性
#a;
constructor() {
this.#a = 'private field';
this.c = 'c';
}
b() {
console.log(`hello ${this.#a} ${this.c}`);
this.#c();
// this.#d();
}
// 私有方法
#c = function(){
console.log('### c');
}
// 语法不正确
// #d() {
// console.log('### d');
// }
}
let cl_a = new a1();
cl_a.b();
// console.log(cl_a.#a);
// console.log(cl_a.#c());
输出:
hello private field c
### c