Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

console.log out a method with template literal in an object

I want to log out all values in the object. every value logs out fine except the value of "description" property.

Here is my code

const cars = {
  make : 'Mazda',
  year : 2015,
  model : 'CX-5',
  style : "SUV",
  drive : 'AWD',
  description : function(){
    return `${this.make} ${this.model} is a capable ${this.drive} ${this.style}`
  }
}
const values = Object.values(cars)

for (const value of values){
  console.log(value)
}

it logsout like this

return ${this.make} ${this.model} is a capable ${this.drive} ${this.style};

instead of this (this is what I want)

Mazda CX-5 is a capable AWD SUV

what can i do to fix this? I need some help.

question from:https://stackoverflow.com/questions/65651232/console-log-out-a-method-with-template-literal-in-an-object

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...