JavaScript ES6类中的私有属性
- 论坛
- JavaScript ES6类中的私有属性
10 浏览
JavaScript ES6类中的私有属性
ES6类中是否可以创建私有属性?以下是一个例子。我如何防止访问instance.property
?
class Something { constructor(){ this.property = "test"; } } var instance = new Something(); console.log(instance.property); //=> "test"
在ES6类中,创建私有属性是可能的吗?下面是一个例子。我该如何防止访问instance.property
?
class Something { constructor(){ this.property = "test"; } } var instance = new Something(); console.log(instance.property); //=> "test"