📜  javascript 类 getter setter - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:49.102000             🧑  作者: Mango

代码示例1
class Porn_Stars{
                   constructor(name,age){
                              this.name = name;
                              this.age = age
                   };
                        get get_data () {
                              return this.name;
                        };
                        set change_data (value) {
                              this.name = value;
                        }

             };
              const data = new Porn_Stars("Chloe Cherry",21);
                   console.log("This is the name before she has changed > "+data.name+"
"); data.change_data="Chloe Culture"; console.log("After changing the name,"+data.name)