1

I want to compute the full property as a result of the first and last properties in a single step, like so:

const name = {
  first: 'John',
  last: 'Doe',
  full: `${this.first} ${this.last}`, // undefined
}

But name.full is undefined.

What am I doing wrong?

Let Me Tink About It
  • 15,156
  • 21
  • 98
  • 207

1 Answers1

4

const name = {
  first: 'John',
  last: 'Doe',
  get full() {
     return `${this.first} ${this.last}`;
  }
}
console.log(name.full);
Siddharth Pal
  • 1,408
  • 11
  • 23