JavaScript ES6类中的私有属性是否可以在ES6类中创建私有属性?下面是一个例子。如何防止访问instance.property?class Something {
constructor(){
this.property = "test";
}}var instance = new Something();console.log(instance.property); //=> "test"
3 回答
慕尼黑5688855
TA贡献1848条经验 获得超2个赞
class Person {
constructor(name) {
var _name = name this.setName = function(name) { _name = name; }
this.getName = function() { return _name; }
}}function Person(name) {
var _name = name this.setName = function(name) { _name = name; }
this.getName = function() { return _name; }}添加回答
举报
0/150
提交
取消
