Object.defineProperty 可以为属性设置get set 访问器
DEMO:
var a= {}
Object.defineProperty(a,"b",{
set:function(newValue){
this.myvalue =newValue;
console.log("set:"+newValue)
},
get:function(){
console.log("get")
return this.myvalue;
}
})
console.log(a.b);//123
a.b ="d"
console.log(a.b);