var person = { usename : "wade", _age : "18", get age (){ return this._age; }, set age(val){ if(val < 0 || val > 100){ throw new Error("年龄不合实际"); }else{ return this._age; } } }; console.log(person.age);
时间: 2024-10-06 00:38:43
var person = { usename : "wade", _age : "18", get age (){ return this._age; }, set age(val){ if(val < 0 || val > 100){ throw new Error("年龄不合实际"); }else{ return this._age; } } }; console.log(person.age);