对象中 set 与get 的用法
<script type="text/javascript"> var p = { name:"chen", work:function() { console.log("wording..."); }, _age:18, get age(){ return this._age; }, set age(val) { if (val<0 || val> 100) {//如果年龄大于100就抛出错误 throw new Error("invalid value") }else{ this._age = val+'岁了'; } } }; p.age = 20 console.log(p.age);//输出chen </script>