T
T
tj572018-10-20 23:41:57
React
tj57, 2018-10-20 23:41:57

Why doesn't babel render the template in react inside a string?

I have a class with a couple of methods:

class Person {
  constructor(name = 'Anonymous', age = 0) {
    this.name = name;
    this.age = age;
  }
  getGreeting() {
    return 'Hi. I am ${this.name}';
  }
  getDescription() {
    return '${this.name} is ${this.age} year(s) old';
  }
}

I want to display in the console the call of these methods on a new object:
const me = new Person('Andrew Mead', 26);
console.log(me.getGreeting());
console.log(me.getDescription());

As a result, the field value for some reason is not substituted into the template, instead it is displayed just a line of code:
5bcb930406cca177355017.png
There are no errors in the Babel console

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tyzberd, 2018-10-20
@tj57

Template literals are enclosed in backticks (` `) instead of double or single quotes.
https://developer.mozilla.org/en/docs/Web/JavaScript...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question