标签:set ons foo console str amp his animal anim
let _age = 4
class Animal {
construct (type){
this.type = type
}
get age(){
return _age
}
set age(val){
if(val < 7 && val >4){
_age = val
}
}
eat(){
console.log(‘eat food‘)
}
}
let dog = new Animal(‘dog‘)
console.log(dog.age)
dog.age = 6
console.log(dog.age)
console.log(dog._age)
标签:set ons foo console str amp his animal anim
原文地址:https://www.cnblogs.com/qjb2404/p/12204852.html