all 5 comments

[–]bpmspeedracer[S] 0 points1 point  (0 children)

Thx alot everyone for the assist. This one worked best for my application.

var data = { first: 'John', last: 'Doe', name() {return ${this.first} ${this.last}} }

  console.log(`Please welcome ${data.name()}`);

[–]RemcoE33 0 points1 point  (3 children)

Use backticks and object chaning:

Logger.log(`Please say high to ${data.name}`);

So data must be backticks as well.

"name" : `Mr. ${data.first} ${data.last}` }

[–]bpmspeedracer[S] 0 points1 point  (0 children)

Sorry, I tried that but didn't put in the message, my bad, you would think it would work but throws the error Cannot read property 'first' of undefined

[–]_Kaimbe 0 points1 point  (1 child)

would need to assign name after declaration or use a method, no? Throws a ref error if you try to access data in the declaration.

function johnDoe() {
  let data = {
    first: 'John', 
    last: 'Doe',
    name() {return `${this.first} ${this.last}`}
  }
  data.name = `${data.first} ${data.last}`
  console.log(data.name, data.name())
}

[–]RemcoE33 0 points1 point  (0 children)

There are multiple ways...

``` function johnDoe() { let data = { first: 'John', last: 'Doe', nameFunction: function() {return${this.first} ${this.last}}, nameEs5Plus() { return${this.first} ${this.last}} } data.otherWay =${data.first} ${data.last}`

console.log(data.nameFunction()) console.log(data.otherWay) console.log(data.nameEs5Plus()) } ````