ES6 / ECMA6模板文字 – 无效
我想尝试使用模板文字并且它不起作用:它显示文字变量名称而不是值。 我使用的是Chrome v50.0.2(和jQuery)。
例:
console.log('categoryName: ${this.categoryName}\ncategoryElements: ${this.categoryElements} ');
输出:
${this.categoryName} categoryElements: ${this.categoryElements}
JavaScript 模板文字需要反引号,而不是直引号。
您需要使用反引号(也称为“严重重音” – 您将在1键旁边找到) – 而不是单引号 – 来创建模板文字。
反引号在许多编程语言中很常见,但对JavaScript开发人员来说可能是新手。
示例 :
categoryName="name"; categoryElements="element"; console.log(`categoryName: ${this.categoryName}\ncategoryElements: ${categoryElements} `)
输出 :
VM626:1 categoryName: name categoryElements: element
请参阅: JavaScript中反引号符号(`)的用法是什么?
1.)将.jshitrc与app.js和其他文件相同的文件夹级别添加
2.)将其放入新创建的文件{“esversion”:6}
3.)永远不要使用单引号“使用反引号”