set $age之后,运行man.age值为undefined
var man = {
name:'kkk',
weibo:'@Bosn',
$age:null,
get age(){
if( this.$age == undefined ){
return new Date().getFullYear() - 1988;
}
},
set age(val){
val = +val;
if( !isNaN(val) && val > 0 && val < 150){
this.$age = +val;
return this.$age;
}else{
console.log('Age can\'t be set to ' + val );
}
}
}
console.log( ' man.age = '+ man.age); // 20
man.$age = 100;
console.log( ' man.age2 = '+ man.age); // undefined 这个我运行出来是undefined,老师的为啥是 100 ,