Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Person {
  2.   constructor(first, last) {
  3.     this._first = first;
  4.     this._last = last;
  5.   }
  6.  
  7.   get firstName() {
  8.     return this._first;
  9.   }
  10.  
  11.   set firstName(name) {
  12.     return (this._first = name);
  13.   }
  14.  
  15.   get lastName() {
  16.     return this._last;
  17.   }
  18.  
  19.   set lastName(name) {
  20.     return (this._last = name);
  21.   }
  22.  
  23.   get fullName() {
  24.     return `${this.firstName} ${this.lastName}`;
  25.   }
  26.  
  27.   set fullName(name) {
  28.     let names = name.split(" ");
  29.     if (names.length === 2) {
  30.       this.firstName = names[0];
  31.       this.lastName = names[1];
  32.     }
  33.     return `${this.firstName} ${this.lastName}`;
  34.   }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement