class UserInfo{
constructor(info){
this.username=info.username;
this.age=info.age
}
getInfo(key){
return this[key]
}
setInfo(key,value){
this[key]=value
}
}
const userInfo=new UserInfo({
username:"geyao",
age:"18"
})
console.log(userInfo.getInfo("username"))
console.log(userInfo.getInfo("age"))
console.log(userInfo.setInfo("username","fangfang"))
console.log(userInfo.getInfo("username"))
console.log(userInfo.getInfo("age"))
运行结果