1. class Person{
    2. value = "html"
    3. get val(){
    4. return this.value;
    5. }
    6. set val(value){
    7. this.value = value
    8. }
    9. }
    10. var p = new Person("cheng",18);
    11. p.val = "good"; //调用set方法
    12. console.log(p)
    1. console.log(p)