实现用方法访问私有变量的函数
1. 通过defineProperty实现
obj = {
name: 'kobe',
getName: function(){
return this.name;
}
}
Object.defineProperty(obj, 'name', {
// 不可枚举不可配置
}) 2. 通过函数的创建形式
function product(){
var name = 'Kobe';
this.getName = function(){
return name;
}
}
var obj = new product(); 
京公网安备 11010502036488号