es3设置属性不能修改
/*es3*/ { var Person =function () { var data ={ name:'zs', sex:'男', age:18 } this.get=function (key) { return data[key]; } this.set =function (key,value) { if(key !=='sex'){ data[key]=value; } } } //声明一个实例 var person = new Person(); //读取 console.table({ name:person.get('name'), sex:person.get('sex'), age:person.get('age') }); person.set('name','es3-cnme'); person.set('sex','female'); person.set('age',22) console.table({ name:person.get('name'), sex:person.get('sex'), age:person.get('age') }); }
效果图: