get set 方法

 1 var man = {
 2     "name": "liushuanhua",
 3   get age() {
 4       return (new Date()).getFullYear() - 1991 
 5   },
 6   set age(val) {
 7       console.log("you can\'t be set to " + val)
 8   }
 9 }
10 console.log(man.age) // 25
11 man.age = 1000; // you can't be set to 1000
12 console.log(man.age) // 25

 

posted @ 2016-02-17 15:59  bronana  阅读(195)  评论(0编辑  收藏  举报