Getter Setter method in ES6

Getter Setter method in ES6

<script>

          let user = {

        name: “Etude”,

        surname: “pro”,

        get fullName() {

          return this.name + ”  ” + this.surname;

        },

        set fullName(value) {

          [this.name, this.surname] = value.split(” “);

        },

        set fullName1(obj) {

          this.name = obj.firstName;

          this.surname = obj.lastName;

        },

      };

      alert(user.fullName);

      user.fullName = “shairy kalra”;

      alert(user.name);

      alert(user.fullName);

      user.fullName1 = { firstName: “shairy1”, lastName: “kalra1” };

      alert(user.name);

      alert(user.fullName);

</script>

One thought on “Getter Setter method in ES6

Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *

*

*