kstoyanov

02. Person

Oct 4th, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Person(first, last) {
  2.     this.firstName = first;
  3.     this.lastName = last;
  4.  
  5.     Object.defineProperty(this, "fullName", {
  6.         set: function(value) {
  7.             const [newFirst, newLast] = value.split(' ');
  8.             if (!newFirst || !newLast) { return;}
  9.             this.firstName = newFirst;
  10.             this.lastName = newLast;
  11.         },
  12.         get: function () {
  13.             return this.firstName + ' ' + this.lastName;
  14.         }
  15.     })
  16. }
Advertisement
Add Comment
Please, Sign In to add comment