js 访问器 set get

const user = {
    data:{name:"angdh",age:11},
    set age(value){
        if(typeof value != "number"){
            throw new Error("xxx")

        }
        this.data.age = value;
    },
    get age(){
        return this.data.age + ""
    }
};



user.age = 89;

console.log(user.age);


原文地址:https://www.cnblogs.com/angdh/p/14965847.html