Javascript ${this…}不';t在节点v13.14中显示值
有人能告诉我为什么在我执行这段代码时类属性值不出现在控制台中吗?非常感谢Javascript ${this…}不';t在节点v13.14中显示值,javascript,Javascript,有人能告诉我为什么在我执行这段代码时类属性值不出现在控制台中吗?非常感谢 class Pessoa { constructor(nome, idade) { this.nome = nome; this.idade = idade; } Info() { console.log('O meu nome é ${this.nome} e tenho ${this.idade} anos.'); } } p1 = new Pessoa("
class Pessoa
{
constructor(nome, idade)
{
this.nome = nome;
this.idade = idade;
}
Info()
{
console.log('O meu nome é ${this.nome} e tenho ${this.idade} anos.');
}
}
p1 = new Pessoa("Pedro", 49);
p1.Info();
要使用${expression}语法,必须使用`字符,而不是'
类
{
建造商(nome,idade)
{
this.nome=nome;
this.idade=idade;
}
信息()
{
log(`O meu nomeé${this.nome}e tenho${this.idade}anos.`);
}
}
p1=新的Pessoa(“Pedro”,49);
p1.Info()代码>